0
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
  • 3
    Please edit your post to include the HTML of the page you are working with. That will allow us to offer better suggestions for you locators - absolute XPaths are going to be horribly fragile and will give you problems. – Kate Paulk Jun 19 at 11:41
  • 1
    You should also put a genuine question in the body of your post. Explain what happens during script execution. Explain what you've tried and failed with. – SlightlyKosumi Jun 19 at 12:24
  • Since I dont have much reputations, I am just gonna comment in this section. Can you post the whole picture of the page also including the Developers tools page? Would be easier for us to see – Bigyan Devkota Jun 19 at 14:40
  • Don't use absolute xpath. Your DOM could change and so your xpath might break – PDHide Jun 20 at 6:56
  • Agreed with the above -- we need more clarification on the question and more details on what the HTML looks like. Stay away from xpath. If the email address input has an ID, use that or use CSS selectors. Side note, I'd recommend to not use so many thread.sleeps. Instead, review the built-in waits in Selenium (explicit wait or implicit wait). – Lee Jensen Jun 27 at 20:42
1

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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.