1

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?

16
  • Did you try with sleep of 1 or 2 second? Commented Jun 6, 2018 at 12:52
  • @VinitMehta I have a sleep of 5 seconds before this. Commented Jun 6, 2018 at 12:55
  • Check whether form located inside a frame/iframe Commented Jun 6, 2018 at 12:59
  • 1
    There are two possible reasons. 1) Duplicate xpath. 2) May be extra popup is open while entering text into input box. Commented Jun 6, 2018 at 13:21
  • 1
    When you write Xpath in developer console , then how many entries are present ? Have you tried to include both presenceofelement and visibilityofelement Commented Jun 6, 2018 at 13:40

1 Answer 1

1

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");
    
Sign up to request clarification or add additional context in comments.

4 Comments

How element can be clickable if it is not visible? By the way, real problem was duplicate xpath. There was another input with same id but in a div with display:none, and all of this was above my input.
Give it a try and let me know the status
Your code work, because you settled in which segment of code to looking for input, and there is no duplicate input.
Of-coarse that should be the ideal approach through getting granular

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.