'sendKeys' are not working in Selenium WebDriver

后端 未结 12 1583
暗喜
暗喜 2020-12-05 13:36

I am not able to put any value in my application using WebDriver. My application is using frames.

I am able to clear the value of my textbox with driver.findEle

12条回答
  •  南方客
    南方客 (楼主)
    2020-12-05 14:09

    I had a similar problem too, when I used

    getDriver().findElement(By.id(idValue)).clear();
    getDriver().findElement(By.id(idValue)).sendKeys(text);
    

    The value in "text" was not completely written into the input. Imagine that "Patrick" sometimes write "P" another "Pat",...so the test failed

    The fix is a workaround and uses JavaScript:

    ((JavascriptExecutor)getDriver()).executeScript("$('#" + idValue + "').val('" + value + "');");
    

    Now it is fine.

    Instead of

    driver.findElement(By.id("idValue")).sendKeys("text");
    

    use,

    ((JavascriptExecutor)getDriver()).executeScript("$('#" + "idValue" + "').val('" + "text" + "');");
    

    This worked for me.

提交回复
热议问题