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

发布于 2024-09-05 09:08:15 字数 265 浏览 3 评论 0原文

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

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

这会返回一个空字符串。

但是,Firefox 内同一页面上的相同 xpath(使用“View XPath”扩展)会产生正确的值。

我尝试过摆弄它,但其他属性(例如@class)也会发生同样的情况——硒有什么严重的错误吗?还是我在这里忽略了一些微不足道的东西?

I'm trying to get the first href attribute in a page using Selenium RC (in Python):

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

this returns an empty string.

However, an identical xpath on the same page inside Firefox (using the "View XPath" extension) yields the correct value.

I've tried fiddling with it, but the same happens for other attributes (eg @class) -- is there something awfully wrong with selenium or am I overlooking something trivial here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

热情消退 2024-09-12 09:08:15

通过使用 selenium 的 get_attribute 来解决,例如节点的 sel.get_attribute("xpath=//a@href")

Solved by using selenium's get_attribute e.g. sel.get_attribute("xpath=//a@href") for a nodes.

超可爱的懒熊 2024-09-12 09:08:15

在 Selenium RC 中,您可以使用 get_attribute 函数,如下所示。

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=

In Selenium RC, you can use the get_attribute function as below.

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

where //li[@id='result_0']/div/div[3]/div/a is the xpath.

xpath= is not required inside the function.

等待圉鍢 2024-09-12 09:08:15

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

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

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

I think this applies to all types of elements:

For example: for an input type of element

selenium.getAttribute("//input@value");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文