Selenium cannot find element

I am trying to find an element on a website using Selenium. The page I'm looking at looks like this:

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

Specifically, I am trying to find an element for a Last Name input field and send keys in Java. html looks like this for a textbox:

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

      

So I first tried to get the item via a unique ID:

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

      

However, it threw the following error:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Cannot find element with id == ctl62_txtSearchLastName (WARNING: Server did not provide any stack information)

I also tried using the name, which came out in a similar way. Since this is a javascipt page, I thought I might have to wait before trying to access the element. I tried explicit and implicit wait and both resulted in timeouts. My next thought was that I was in the wrong frame, but I cannot find another frame. I tried indexing as I have no names, but I couldn't find other frames. This is at the top of the page, which could be messy 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 find an item? Any help would be greatly appreciated /

+3


source to share


1 answer


Using 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");

      



Result:

enter image description here

+7


source







All Articles