python - 如何查找元素的xpath、类名 python selenium

标签 python selenium xpath classname

我的代码是:

driver.get("http://www.thegoodguys.com.au/buyonline/SearchDisplay?pageSize=16&beginIndex=0&searchSource=Q&sType=SimpleSearch&resultCatEntryType=2&showResultsPage=true&pageView=image&searchTerm=laptops")
link=();
linkPrice=();
price=();
productName=[];
Site='Harvey Norman'
link=driver.find_elements_by_class_name("photo")

linkPrice=driver.find_elements_by_class_name("product-title")

price=driver.find_elements_by_xpath("//div[@class='purchase']/span/span") 

我不确定提供的 xpath 和 class_name 是否正确。有人可以验证一下它们吗?请告诉我如何找到它们

最佳答案

在 Firefox 中,您只需使用 developer toolsfirebug检查 html 中的类和元素 id。继link在你的问题中,我可以找到一个名为 photo 的类,但对于 linkPrice 和 Price,你应该使用其他类。

尝试:

price=driver.find_elements_by_class_name("price")
linkPrice=driver.find_elements_by_class_name("addtocart")

这给了我:

price[0].text
u'$496'
linkPrice[0].text
u'ADD TO CART'

关于python - 如何查找元素的xpath、类名 python selenium,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24277313/

相关文章:

java - Java 中用于获取 xml 元素的 XPath 表达式

python - 编译SCSS时默认导入常用模块

python - 文本文件解释

python - 这个 selenium firefox 配置文件将文件下载到自定义文件夹有什么问题?

xml - BaseX 上的 Xpath/Xquery 没有返回任何结果

selenium - 如何在 RIDE 中单击单击事件上具有 javascript 的行

python - 如何使用 scrapy Selector 获取节点的 innerHTML?

python - 如何在Python中使用websocket api?

javascript - Selenium IDE - 将 URL 字符串变量传递到条件 'gotoIf' 语句会引发语法错误?

python - 即使使用 ui.WebDriverWait() chrome selenium python 后也会出现随机 TimeoutException