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.
Here is the code:
driver.findElement(By.xpath("//label[text()='User Name:']/following::div/input")).sendKeys("UserName");
driver.findElement(By.xpath("//label[text()='User Name:']/following::div/input")).sendKeys(Keys.TAB);
But this one is not working.
This question is related to
java
selenium
selenium-webdriver
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());
}
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()
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
.
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");
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).
Try this code:
WebElement userName = pathfinderdriver.switchTo().activeElement();
userName.sendKeys(Keys.TAB);
Try this, it will surely work:
driver.findElement(By.xpath("//label[text()='User Name:']/following::div/input")).sendKeys("UserName" + Keys.TAB);
I believe Selenium now uses Key.TAB
instead of Keys.TAB
.
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);
This is a single line command to send the TAB key;
driver.findElement(By.id("Enter_ID")).sendKeys("\t");
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");
Source: Stackoverflow.com