使用硒的XPath无法找到“文本”元素 [英] Using Selenium, xpath cannot find 'text' element

查看:226
本文介绍了使用硒的XPath无法找到“文本”元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来硒,有一个问题,通过XPath查找的元素。我试图解决这个问题,但花了太多时间在上面,它仍然无法正常工作。

I'm new to Selenium and have a problem to find an element by XPath. I was trying to handle this issue but spent too much time on it and it still doesn't work.

我想自动化文件从网站。

I'm trying to automate file downloading from this site.

我在寻找包含版本名称事后我需要相应地点击下载图标元素。

I'm searching for the element which contain version name and afterwards I need to click the download icon accordingly.

我为了找到元素正在写下面的code

I'm writing the following code in order to find element

var element1 = driver.FindElement(By.XPath("//*[@id='versiontable']/div[3]/a[Text()='Firefox 22.0 (Beta 2)']"));

但是,这是行不通的,元素不能被发现。

However, it doesn't work, element cannot be found.

和之后,我需要相应地点击下载图标。我不知道如何单击元素,它是相关的Firefox最新版本。有什么建议?

And after I need to click a download icon accordingly. I'm not sure how to click element which is relevant for current version of firefox. Any suggestions?

推荐答案

所有的XPath函数的第一个文本()已书面小写。结果
另外你正在寻找的链接项不是三(3)DIV。

First of all the xpath function text() has to written in lowercase.
Also the link entry you are looking for is not the third (3) div.

由于直接下载是符合CLASS =权利在div的链接。结果
请试试这个:

Because the direct download is the link in the div with class="right".
Please try this:

"//div[div/a[text()='Firefox 22.0 (Beta 2)']]/div[@class='right']/a"

这篇关于使用硒的XPath无法找到“文本”元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆