sendKeys() in Selenium web driver

前端 未结 11 1695
野性不改
野性不改 2020-12-31 04:23

I am new to Selenium. I just want to send keys to a username text box and send a tab key both at a time so that text box can check for availability of username.

相关标签:
11条回答
  • 2020-12-31 05:14

    This is a single line command to send the TAB key;

    driver.findElement(By.id("Enter_ID")).sendKeys("\t");
    
    0 讨论(0)
  • 2020-12-31 05:15

    I doubt for Keys.TAB in sendKeys method... if you want to use TAB you need to do something like below:

    Actions builder = new Actions(driver);
    builder.keyDown(Keys.TAB).perform()
    
    0 讨论(0)
  • 2020-12-31 05:22

    Try this one, and then import the package:

    import org.openqa.selenium.Keys;
    
    driver.findElement(By.xpath("//*[@id='username']")).sendKeys("username");
    
    driver.findElement(By.xpath("//*[@id='username']")).sendKeys(Keys.TAB);
    
    driver.findElement(By.xpath("//*[@id='Password']")).sendKeys("password");
    
    0 讨论(0)
  • 2020-12-31 05:25

    Try using Robot class in java for pressing TAB key. Use the below code.

    driver.findElement(By.xpath("//label[text()='User Name:']/following::div/input")).sendKeys("UserName");
    
    Robot robot = new Robot();
    robot.keyPress(KeyEvent.VK_TAB);
    robot.keyRelease(KeyEvent.VK_TAB);
    
    0 讨论(0)
  • 2020-12-31 05:27

    The simplest solution is Go to Build Path > Configure Build Path > Java Compiler and then select the 'Compiler compliance level:' to the latest one from 1.4 (probably you have this).

    0 讨论(0)
提交回复
热议问题