not any locator works My Email address field are not fields automatically in testing selenium on login page



  • import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    
    
    public class Medika_login {
    
        public static void main(String[] args) throws InterruptedException {
    
            System.setProperty("webdriver.chrome.driver","C:\\Users\\my_pc\\Desktop\\Prasad Selenium\\Driver for browser\\chromedriver.exe");
            Thread.sleep(3000);
            WebDriver driver1 = new ChromeDriver();
            Thread.sleep(3000);
            driver1.get("http://www.medikabazaar.com");
            Thread.sleep(3000);
            //Close ViZi Pop-up
            driver1.findElement(By.xpath("//*[@id='x']")).click();
            Thread.sleep(3000);
            //Click on Sign Up
            driver1.findElement(By.xpath("/html/body/div[1]/header/div/div[1]/div[5]/div[3]/a/span[2]")).click();
            Thread.sleep(3000);
            //Log in to Medikabazaar.com
            driver1.findElement(By.xpath("/html/body/div[1]/header/div/div[1]/div[5]/div[3]/div/ul/li[1]/a/span")).click();
            Thread.sleep(3000);
    
            System.setProperty("webdriver.gecko.driver","C:\\Users\\my_pc\\Desktop\\Prasad Selenium\\Driver for browser\\geckodriver.exe");
            WebDriver driver = new FirefoxDriver();
            Thread.sleep(3000);
            //goto Medikabazaar.com
            driver.get("http://www.medikabazaar.com");
            Thread.sleep(3000);
            //Close ViZi Pop-up
            driver.findElement(By.xpath("//*[@id='x']")).click();
            Thread.sleep(3000);
            //Click on Sign Up
            driver.findElement(By.xpath("/html/body/div[1]/header/div/div[1]/div[5]/div[3]/a/span[2]")).click();
            Thread.sleep(3000);
            //Log in Page
            driver.findElement(By.xpath("/html/body/div[1]/header/div/div[1]/div[5]/div[3]/div/ul/li[1]/a/span")).click();
            Thread.sleep(3000);
    
            //Login Page
            //User Email
            WebElement element = driver.findElement(By.xpath("//*[@id='email']"));
            Thread.sleep(3000);
            element.sendKeys("xxxxxxxxxxxxxxxxx@gmail.com");
            Thread.sleep(3000);
            //element.submit();
            driver.findElement(By.name("login[username]")).sendKeys("xxxxxxxxxxxxxxxxx@gmail.com");
            //User Password
    
            //Click on Login Button
    


  • I will mirror what others are saying in the comments below - you need to post the HTML of the site you are using, for the item you are using. Posting the place where the error is happening is also very important for us to help you debug.

    This locator /html/body/div[1]/header/div/div[1]/div[5]/div[3]/a/span[2] on click sign up is very brittle.

    Looking at the website you have listed as here

    You could use the class reference

    <span class="sign">Sign In</span>
    

    by referencing the class and the text - allowing you to have a more concrete reference. Something like this:

    (By.xpath("//span[@class='sign'][contains(text(), 'Sign In')]").click();



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2