Reputation: 53
When I inspected my page in chrome, I get this:
<input class="form-control form-text required" title="" data-toggle="tooltip" type="text" id="edit-name" name="name" value="" size="60" maxlength="60" data-original-title="Enter your username.">
I right clicked on this code and selected Copy > Xpath. I got this:
//*[@id="edit-name"]
I created a variable:
final By userNameField = By.xpath ("//*[@id="edit-name"]");
I get syntax error.
Then I tried this by id
public void enterUserName(){
driver.findElement(By.id("edit-name")).sendKeys("admin");
System.out.println("User name is entered");
}
It entered the user name just fine. How do I find the correct xpath in chrome so I can create a variable like I tried in step 1?
Upvotes: 0
Views: 4725
Reputation: 391
final By userNameField = By.xpath ("//*[@id="edit-name"]");
You've got double quotes inside your quotes. change to:
final By userNameField = By.xpath ("//*[@id='edit-name']");
Upvotes: 1