sendKeys() in Selenium web driver

前端 未结 11 1694
野性不改
野性不改 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:00

    Try this code:

    WebElement userName = pathfinderdriver.switchTo().activeElement();
    userName.sendKeys(Keys.TAB);
    
    0 讨论(0)
  • 2020-12-31 05:02
    List<WebElement>itemNames = wd.findElements(By.cssSelector("a strong")); 
    System.out.println("No items in Catalog page: " + itemNames.size());
       for (WebElement itemName:itemNames)
        {  
           System.out.println(itemName.getText());
        }
    
    0 讨论(0)
  • 2020-12-31 05:03

    I have found that creating a var to hold the WebElement and the call the sendKeys() works for me.

    WebElement speedCurrentCell = driver.findElement(By.id("Speed_current"));
    speedCurrentCell.sendKeys("1300");
    
    0 讨论(0)
  • 2020-12-31 05:04

    I believe Selenium now uses Key.TAB instead of Keys.TAB.

    0 讨论(0)
  • 2020-12-31 05:05

    Try this, it will surely work:

    driver.findElement(By.xpath("//label[text()='User Name:']/following::div/input")).sendKeys("UserName" + Keys.TAB);
    
    0 讨论(0)
  • 2020-12-31 05:06

    For python selenium,

    Importing the library,

    from selenium.webdriver.common.keys import Keys
    

    Use this code to press any key you want,

    Anyelement.send_keys(Keys.RETURN)
    

    You can find all the key names by searching this selenium.webdriver.common.keys.

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