Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium can't send keys in found element

I have an element with this outerHtml -

<input class="inp-text ps-component ng-valid-maxlength ng-touched ng-pristine ng-empty ng-invalid ng-invalid-required" ng-model-options="{ updateOn: 'default blur', debounce: { 'default': 200, 'blur': 0 } }" required="required" maxlength="100" ng-model="model.name"/>

I had tried -

driver.findElement(By.cssSelector("input"));

can find this element, but when I try to do

driver.findElement(By.cssSelector("input")).sendKeys("something");

java tell me that the element is not visible exception

driver.findElement(By.cssSelector("input")).click(); 

don't work too.

How to send some keys in this input element?

I found a part of solution. click() work if use it:

WebElement input = driver.findElement(By.cssSelector("input"))
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", input);

But I still don't understand how to send keys in it.

like image 355
Beras Mark Avatar asked Sep 12 '25 05:09

Beras Mark


1 Answers

Try using explicit wait with Expected Conditions to make sure the element is visible before interacting with it

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input")));
element.sendKeys("something");
like image 102
Guy Avatar answered Sep 13 '25 20:09

Guy