I am working in Selenium. And I have got an error unable to locate element username. I'm using Java language. I am following page object design pattern.
Here is my code..
Pageobject
@FindBy(how=How.XPATH,using="//*[@id=\'user_name\']")
WebElement username;
public void setUername(String usernam){
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\'user_name\']")));
username.sendKeys(usernam);
}
Steps
AppointmentPage appointmentPageobj= PageFactory.initElements(DriverManager.driver,AppointmentPage.class);
appointmentPageobj.setUername(usernam);
Test
AppointmentPage ex=log.Valid("9845612345","naveen","[email protected]","Demo","2017-03-04","Dr.biju");
Inspect locator:
<input type="text" id="user_name" value="" name="user_name" class="form-control">
Error:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"name","selector":"username"}
(Session info: chrome=56.0.2924.87)
(Driver info: chromedriver=2.25.426924 (649f9b868f6783ec9de71c123212b908bf3b232e),platform=Linux 4.4.0-64-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 193 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700'
System info: host: 'naveen-Inspiron-3542', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-64-generic', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.25.426924 (649f9b868f6783ec9de71c123212b908bf3b232e), userDataDir=/tmp/.org.chromium.Chromium.JfNimh}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=56.0.2924.87, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 650ae51248719121c19384d62127029c
*** Element info: {Using=name, value=username}
I tried to put the locators ID, NAME, XPATH and CSS too. But still same error is coming what to do?
@FindBy(how=How.XPATH,using=".//*[@id='user_name']")
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath_details"))