[英]How to get child element based on parent element in python selenium
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.发生此错误。
I have checked your code and I think there is one mistake on your expression in xpath. I think you have to erase .
我检查了你的代码,我认为你在 xpath 中的表达式有一个错误。我认为你必须删除
.
in xpath expression.在 xpath 表达式中。 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.
谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.