Selenium/python - Clicking all elements which are in a particular div -
i learning scrape using selenium , trying 1 of sap pages.
the link : https://help.sap.com/viewer/2e167338c1b24da9b2a94e68efd79c42/4.2.4/en-us/
what intend leaf/last level urls page present on table of contents panel. unfortunately, links not in html , if click on each side button on left panel, expand, also, each button click can have more nested buttons! need click these , underlying data.
i starting identifying xpath , tried clicking them, gives following error :
import time driver = webdriver.chrome("/users/tarun/downloads/chromedriver") driver.get("https://help.sap.com/viewer/2e167338c1b24da9b2a94e68efd79c42/4.2.4/en-us/") time.sleep(20) #tried htmlsource = driver.page_source buttonssidepanel = driver.find_elements_by_xpath('//*[@id="toc"]/treecontrol/div/div[*]/div[1]/div[1]') #also tried - //*[@id="toc"]/treecontrol/div/div[*]/div[1]/div[1]/span[1] x in buttonssidepanel: x.click() time.sleep(1) driver.close() the error : elementnotvisibleexception: message: element not visible
i have few questions in regard (apologies if of them naive) 1. )the elements visible in html when inspect element! unable figure out doing wrong?
- also, how recursively click underlying buttons if button click shows more buttons, or there way can click buttons @ once , scrape data? looked @ few stackoverflow questions, couldn't resolve task
3.)after clicking button, how scrape newly generated content?
you can try running simple js script using selenium's execute_script. try this.you can alsi identify using class name.
jscode=''' var allbuttons=document.getelementsbyclassname('collapseicon'); for( b of allbuttons){ b.click(); } ''' driver.execute_script(jscode); also scrape including child drop downs, getting page content/response in call below use, request module check this,
import requests url = "https://help.sap.com/http.svc/getpagecontent?deliverableinfo=1&deliverable_loio=2e167338c1b24da9b2a94e68efd79c42&language=en-us&state=production&toc=1&version=4.2.4" r = requests.get(url) print (r.json()) wiki
Comments
Post a Comment