无法使用 XPath 查找元素 - NoSuchElementException

雅科夫·泰维尔

我试图在 C# 中使用 Selenium Web 驱动程序查找元素。我的代码是:

var pathToLinkGeneral = Driver.FindElement(By.XPath("//div[@class='form-control'][label[text()='Get direct link:']]/input"));

页面中的源代码是:

<div class="form-group">
<label>Get direct link:</label>
<input class="form-control" type="text" style="cursor: auto; value="http://ds2.dev.polebeary.com/api/download/1521723231257836/qa_yaakov_tevel.dmg" readonly="">

但我不断收到此异常-

Message: Test method UnitTestProject1.UnitTest1.TestMethod1 threw exception: OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@class='form-control'][label[text()='Get direct link:']]/input"} 

任何人都可以帮忙吗?

阿南德

这应该有帮助:

var pathToLinkGeneral = Driver.FindElement(By.XPath("//div[@class='form-group'][label[text()='Get direct link:']]/input"));

您需要表单组,而不是控制。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章