I had to re-test the xpath
, Previously it was working fine, But now it gives me an error.
I tried with different locators as well, Like id
, name
. but still get the same error.
package staging;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class login {
public static void main (String[]args){
System.setProperty("webdriver.gecko.driver","C:\\Program Files\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
//opening the browser
driver.get("https://staging.keela.co/login");
//logging
driver.findElement(By.xpath("//*[@id='login-email']")).sendKeys("bandanakeela@yopmail.com");
driver.findElement(By.xpath("//*[@id='login-password']")).sendKeys("keela");
driver.findElement(By.xpath("//*[@id='login-form']/div[3]/div/button")).click();
}
}
The page is using js to construct elements. So I would suggest you to use phantomjs driver.
Then you have to wait until element exist. You see the gear icon when page is loading. wait until the element loads. and also you can use id instead of xpath since you know your element id .
You can choose which wait type you want to use. Explicit Waits or Implicit Waits.
Here is the selenium documentation.
and example code for wait:
or you can wait until page load:
Try this below code.
Note: If
id
attribute is available then you should useid
and forxpath
try to use relativexpath
.I have used explicit wait method, so your driver may able to find the next
webelement
, after page is fully loaded.As you access the url
https://staging.keela.co/login
there is a Ajax loader which blocks the UI, so we have to wait for the Ajax loader to complete loading the all the WebElements and theemail
andpassword
field becomes visible. To achieve that we will introduceExplicitWait
i.e.WebDriverWait
withExpectedConditions
set toelementToBeClickable
for theemail
field.Here is the working code block:You are opening the URL and at the very next moment entering email-id. Before entering email-id, you need to check if the page is fully loaded. In this case, explicit wait will help you out-