Selenium sendkeys drops character with Chrome Driver

后端 未结 4 1511
时光取名叫无心
时光取名叫无心 2021-01-04 06:53

Selenium sendkeys with Chrome Driver drops character \"2\" and \"4\". Other characters are OK. When I use other browser (IE or FF), everything is OK.

code:



        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-04 07:17

    I had the same issue. I ended up calling sendkeys inside a loop until the correct value was inserted. Here's what I did:

    WebElement name = driver.findElement(By.xpath(...));
    this.sendkeys(name,"yourValue");
    
    private void sendkeys(WebElement ele, String val) throws 
    InterruptedException
    {   ele.clear();
        while(true)
        {   ele.sendKeys(val);
            if(ele.getAttribute("value").equals(val))
                break;
            else
            {   ele.clear();
                Thread.currentThread();
                Thread.sleep(3000);
            }
        }
    
        Thread.currentThread();
        Thread.sleep(3000);
    }
    

    Hope this helps.

提交回复
热议问题