Eduardo Fabricio Eduardo Fabricio - 3 months ago 14
jQuery Question

Element after jquery.show and WebDriverException: unknown error: cannot focus element

My javascript line:

$('#name').show();


My webdriver code line:

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("name"))).sendKeys("Some Name");


When I run the test it throws the following exception:

WebDriverException: unknown error: cannot focus element


So, I have been searching for a solution. There are some issues reported in chromium google code site. There are a lot of suggestions about using
JavaScriptExecutor
. But it doesn't seem a better solution for me, because it could make a browser dependent code.

Answer

After some hours I finally found a solution by using Actions without JavascriptExecuter:

Actions actions = new Actions(driver);
actions.moveToElement(website);
actions.click();
actions.sendKeys("Some Name");
actions.build().perform();

Well, it worked for me. However, is this way the better solution ?

Comments