无法使用xpath获取Selenium RC属性的值

2024-04-20 10:19:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用Selenium RC(在Python中)获取页面中的第一个href属性:

sel.get_text("xpath=//@href")

这将返回一个空字符串。在

但是,Firefox中同一页面上的相同xpath(使用“viewxpath”扩展名)会产生正确的值。在

我尝试过修改它,但是其他属性(例如@class)也会发生同样的情况——selenium是不是有什么问题,或者我忽略了一些琐碎的东西?在


Tags: 字符串textget属性selenium情况页面firefox
3条回答

我认为这适用于所有类型的元素:

例如:对于元素的输入类型

selenium.getAttribute("//input@value");

在Selenium RC中,您可以使用如下get_属性函数。在

AttrValue = sel.get_attribute("//li[@id='result_0']/div/div[3]/div/a@href")

其中//li[@id='result_0']/div/div[3]/div/a是xpath。在

函数内不需要xpath=。在

通过使用selenium的get_属性(例如,sel.get_attribute("xpath=//a@href"))来解决。在

相关问题 更多 >