Home > Enterprise >  How to get child element based on parent element in python selenium
How to get child element based on parent element in python selenium

Time:10-03

items = driver.find_elements_by_class_name('gs_or')
for item in items:
   title_temp = item.find_element_by_xpath(".//div[2]/h3/a").text

In this case,

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/div[2]/h3/a"} 

this error is occurred.

CodePudding user response:

I have checked your code and I think there is one mistake on your expression in xpath. I think you have to erase . in xpath expression. So ...

title_temp = item.find_element_by_xpath("//div[2]/h3/a").text

This expression will be work, I think.

Hope to be helpful for you. Thanks.

  • Related