0

I am trying to send information to a textfield and I am having difficulties locating it. There are multiple elements with the same name and it's difficult to find it.

<div class="form-group">
  <label for="username">LDAPTEST Username</label>
  <input type="text" name="username" id="username" class="form-control top" title="This field is required." autofocus="autofocus" data-qa-selector="username_field" required="required">
  <p class="gl-field-error hidden">This field is required.</p> 
</div>

I have tried the following:

username_By = By.id("username")

username_By = By.cssSelector("input[data-qa-selector='username_field']")

I am getting TimeoutException when I am waiting for the visibility of the element.

wait.until(ExpectedConditions.visibilityOfElementLocated(username_By));

Any suggestions on how to locate the element? Thanks

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

1

//label[contains(text(),'LDAPTEST Username')] Please use this xpath to locate elements to send keys

Justin Lambert
  • 940
  • 1
  • 7
  • 13
0

It is a username field possibly you intent to send some text to the desired field. So to send a character sequence to the LDAPTEST Username field, instead of visibilityOfElementLocated() you need to use WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.form-control.top#username[name='username']"))).sendKeys("anibal-bojorquez");
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='form-control top' and @id='username'][@name='username']"))).sendKeys("anibal-bojorquez");
    

Update

Try the following alternatives:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("label[for='username']"))).sendKeys("anibal-bojorquez");
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//label[@for='username']"))).sendKeys("anibal-bojorquez");
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352