【问题标题】:Cant fint element using XPath - NoSuchElementException使用 XPath 找不到元素 - NoSuchElementException
【发布时间】:2018-04-09 11:49:38
【问题描述】:

我试图在 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"} 

谁能帮忙?

【问题讨论】:

  • div 的类是 form-group,而不是 form-control

标签: c# selenium xpath webdriver


【解决方案1】:

这应该会有所帮助:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-20
    • 2022-06-23
    • 1970-01-01
    • 2018-08-30
    • 1970-01-01
    • 1970-01-01
    • 2013-05-21
    • 2017-10-16
    相关资源
    最近更新 更多