5

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();       
 }
}
Jainish Kapadia
  • 2,603
  • 5
  • 18
  • 29
Bandana Singh
  • 95
  • 1
  • 4
  • 10

4 Answers4

5

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 the email and password field becomes visible. To achieve that we will introduce ExplicitWait i.e. WebDriverWait with ExpectedConditions set to elementToBeClickable for the email field.Here is the working code block:

System.setProperty("webdriver.gecko.driver","C:\\Utility\\BrowserDrivers\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://staging.keela.co/login");
WebDriverWait wait = new WebDriverWait (driver, 15);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='login-email']")));
element.sendKeys("bandanakeela@yopmail.com");
driver.findElement(By.xpath("//input[@id='login-password']")).sendKeys("keela");
driver.findElement(By.xpath("//button[@class='btn btn-sm btn-block btn-primary']")).click(); 
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Can you please explain, why are you using `xpath` locator here. If `id` attribute is present. This does not make any sense for me..!!! and for your kind information `id` attribute is one of the fastest locator to finding a `webelement`. – Jainish Kapadia Sep 14 '17 at 06:48
1

Try this below code.

Note: If id attribute is available then you should use id and for xpath try to use relative xpath.

I have used explicit wait method, so your driver may able to find the next webelement, after page is fully loaded.

driver.get("https://staging.keela.co/login");
driver.manage().window().maximize();

//Explicit wait for 60 seconds, to find the webelement. You can increase or decrease the time as per your specification.        
new WebDriverWait(driver, 60).until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("login-email"))));
driver.findElement(By.id("login-email")).sendKeys("bandanakeela@yopmail.com");
driver.findElement(By.id("login-password")).sendKeys("keela");
driver.findElement(By.xpath("//button[@type='submit'][text()='Log in']")).click();
Jainish Kapadia
  • 2,603
  • 5
  • 18
  • 29
0

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:

WebElement myDynamicElement = (new WebDriverWait(driver, 10))
  .until(ExpectedConditions.presenceOfElementLocated(By.id("login-email")));

or you can wait until page load:

new WebDriverWait(firefoxDriver, pageLoadTimeout).until(
          webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));
  • Thanks its working but only in part of sendkeys..data are provided but login button is not clicked – Bandana Singh Sep 14 '17 at 06:21
  • I just added the wait examples , that is why :) You were unable to see the elements and your question's answer was waiting until element is exist. –  Sep 14 '17 at 19:28
0

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-

//opening the browser
driver.get("https://staging.keela.co/login");

//Explicit wait

WebDriverWait wait = new WebDriverWait(WebDriverRefrence,20);
WebElement email;
email = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("login-email")));

//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();
Kapil
  • 397
  • 4
  • 6