Hi,
I would like to write an xpath expression to ONLY print the text for all the "class - insights type1". I don't need to print the ones that has "hide" .
Following CSS selector gives me all the tags for the Insights popup
driver.find_elements_by_css_selector("#body > div.side-module.expanded > div.content")
Can someone help with this please?
Thanks
Here's how you can do this:
//div[@class="content"]/div[@class="insights type1"]
In python call find_elements_by_xpath()
and get the text of each div found:
for div in driver.find_elements_by_xpath('//div[@class="content"]/div[@class="insights type1"]'):
print div.text
Note that if you need only one single div, use just find_element_by_xpath()
:
div = driver.find_element_by_xpath('//div[@class="content"]/div[@class="insights type1"]')
print div.text
Also, if these div
s can be outside of content
div
too - use //div[@class="insights type1"]
.
Hope that helps.
You can use Chrome's Dev Tools for this.
Fire up the dev tools using F12, and just right-click the element whose xpath you want.
Then use lxml to process the xml tree.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.