KunLun
KunLun

Reputation: 3225

Selenium can't find element which is visible

This is HTML where I try to find selected input

HTML

I try to sendkey() to this input like this

String xPath = "//*[@id='id_username']";

WebDriverWait wait = new WebDriverWait(driver, 30);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xPath))).sendKeys("text");

Always get this error org.openqa.selenium.TimeoutException. Usually I get this error when element is not visible in setted time.

There is no iframe in entire html.

Which may be the cause?

Upvotes: 1

Views: 2261

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193058

You need to consider a couple of points as follows:

  • Instead of String try to define the xpath as an object of By.
  • Moving forward as you are invoking sendKeys() instead of ExpectedConditions method visibilityOfElementLocated() use elementToBeClickable() method.
  • As the element is an <input> try to construct a granular xpath
  • Your code block will be as:

    By xPath = By.xpath("//form[@action='/accounts/register/']/fieldset[@class='fieldset_main']//input[@id='id_username' and @name='username']");
    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(xPath)).sendKeys("text");
    

Upvotes: 1

Related Questions