NoSuchElementException, Selenium unable to locate element

前端 未结 3 725
滥情空心
滥情空心 2020-11-21 06:09

i would like to find my TextField in selenium, but i dont know how (i use sellenium for the first time).

I tried:

 driver.findElement(By.id(\"originT         


        
3条回答
  •  盖世英雄少女心
    2020-11-21 06:45

    NoSuchElementException

    org.openqa.selenium.NoSuchElementException popularly known as NoSuchElementException extends org.openqa.selenium.NotFoundException which is a type of WebDriverException.

    NoSuchElementException can be thrown in 2 cases as follows :

    • When using WebDriver.findElement(By by) :

      //example : WebElement my_element = driver.findElement(By.xpath("//my_xpath"));
      
    • When using WebElement.findElement(By by) :

      //example : WebElement my_element = element.findElement(By.xpath("//my_xpath"));
      

    As per the JavaDocs just like any other WebDriverException, NoSuchElementException should contain the following Constant Fields :

    Constant Field      Type                                        Value
    SESSION_ID          public static final java.lang.String        "Session ID"
    e.g. (Session info: chrome=63.0.3239.108)
    
    DRIVER_INFO         public static final java.lang.String        "Driver info"
    e.g. (Driver info: chromedriver=2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1),platform=Windows NT 6.1.7601 SP1 x86)
    
    BASE_SUPPORT_URL    protected static final java.lang.String     "http://seleniumhq.org/exceptions/"
    e.g. (For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html)
    

    Reason

    The reason for NoSuchElementException can be either of the following :

    • The Locator Strategy you have adopted doesn't identifies any element in the HTML DOM.
    • The Locator Strategy you have adopted is unable to identify the element as it is not within the browser's Viewport.
    • The Locator Strategy you have adopted identifies the element but is invisible due to presence of the attribute style="display: none;".
    • The Locator Strategy you have adopted doesn't uniquely identifies the desired element in the HTML DOM and currently finds some other hidden / invisible element.
    • The WebElement you are trying to locate is within an