代码之家  ›  专栏  ›  技术社区  ›  Yaakov Tevel

无法使用XPath查找元素-NoSuchElementException

  •  -1
  • Yaakov Tevel  · 技术社区  · 6 年前

    我正在尝试使用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"} 
    

    有人能帮忙吗?

    1 回复  |  直到 6 年前
        1
  •  0
  •   Anand    6 年前

    这将有助于:

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

    您需要窗体组,而不是控件。