Selenium Webdriver: Entering text into text field

前端 未结 4 1726
遇见更好的自我
遇见更好的自我 2020-12-03 16:45

When I enter text into the text field it gets removed.

Here is the code:

String barcode=\"0000000047166\";

WebElement element_enter = _driver.findEl         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 17:14

    I had a case where I was entering text into a field after which the text would be removed automatically. Turned out it was due to some site functionality where you had to press the enter key after entering the text into the field. So, after sending your barcode text with sendKeys method, send 'enter' directly after it. Note that you will have to import the selenium Keys class. See my code below.

    import org.openqa.selenium.Keys;
    
    String barcode="0000000047166";
    WebElement element_enter = driver.findElement(By.xpath("//*[@id='div-barcode']"));
    element_enter.findElement(By.xpath("your xpath")).sendKeys(barcode);
    
    element_enter.sendKeys(Keys.RETURN); // this will result in the return key being pressed upon the text field
    

    I hope it helps..

提交回复
热议问题