Selenium Unable to Find Element

23,426

Using an explicit wait worked for me (tried both chrome and firefox):

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(
    ExpectedConditions.visibilityOfElementLocated(By.id("ctl62_txtSearchLastName"))
);

element.sendKeys("test");

Resulted into:

enter image description here

Share:
23,426
klib
Author by

klib

Interested in many different programming languages. Current areas of work include web scraping, big data, and web apps.

Updated on July 09, 2022

Comments

  • klib
    klib almost 2 years

    I am trying to find an element on a website using Selenium. The page I am looking at is:

    http://www.usaswimming.org/DesktopDefault.aspx?TabId=1470&Alias=Rainbow&Lang=en-US

    Specifically I am trying to find the element for the "Last Name" input box and send keys in Java. the html looks like this for the text box:

    <div class="field">
    <input id="ctl62_txtSearchLastName" type="text" maxlength="36" name="ctl00$ctl62$txtSearchLastName">
    </div>
    

    Therefore, I initially attempted to get the element through the id which is unique:

    WebDriver driver = new InternetExplorerDriver();
    driver.get(timeSearchSite);
    ...
    driver.findElement(By.id("ctl62_txtSearchLastName")).sendKeys(lastName);
    

    However this generated the following error:

    Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with id == ctl62_txtSearchLastName (WARNING: The server did not provide any stacktrace information)

    I also tried to use the name which failed similarly. Since this is a javascipt page I thought that I might need to wait before trying to access the element. I tried an explicit and an implicit wait and both resulted in timeouts. My next thought was that I was in the wrong frame but I cannot seem to find another frame. I tried indexing since I don't have names but I couldn't locate any other frames. There is this at the top of the page which might be messing selenium up:

    <noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-WMWM93" height="0" width="0"           
    style="display: none; visibility: hidden"></iframe></noscript>
    

    What could be causing this error? How can I locate the element? Any help would be greatly appreciated/