0

I am trying to automate the Registration and Login process of Myntra.com using selenium.

I already registered once using selenium. But the problem is when i am trying to register once more using the same userId and password, a popup is generating saying "email-id already exist". I want to handle this popup .That if this particular text is present then i'll go to login page. But i'm unable to handle that popup.

Attached the screenshot of the popup

Using the following code :

   public class Myntra {

    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver","D://Selenium/Selenium Setup/chromedriver.exe");
        WebDriver Driver= new ChromeDriver();

        Driver.manage().window().maximize();
        Driver.get("https://www.google.co.in");
        Driver.findElement(ByXPath.id("lst-ib")).sendKeys("myntra");
        Driver.findElement(ByXPath.id("lst-ib")).sendKeys(Keys.ENTER);

        List<WebElement> findElements = Driver.findElements(ByXPath.xpath("//*[@id='rso']//h3/a"));
        for (WebElement webElement : findElements)
        {
             if(webElement.getAttribute("href").equalsIgnoreCase("https://www.myntra.com/")) {
                Driver.navigate().to(webElement.getAttribute("href"));
                System.out.println("Navigation Success");
                break;
             }
        }
        Driver.findElement(ByXPath.xpath("//*[@id=\"desktop-header-cnt\"]/div[2]/div[2]/div/div[1]")).click();
        Driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        Driver.findElement(ByXPath.xpath("//*[@id=\"desktop-header-cnt\"]/div[2]/div[2]/div/div[2]/div[2]/div[2]/a[1]")).click();

        //Register page

        Driver.findElement(ByXPath.name("email")).sendKeys("[email protected]");
        Driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        Driver.findElement(ByXPath.name("password")).sendKeys("123");
        Driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        Driver.findElement(ByXPath.name("mobile")).sendKeys("1234567892");
        Driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        Driver.findElement(ByXPath.id("male")).click();
        Driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        Driver.findElement(ByXPath.xpath("//*[@id=\"mountRoot\"]/div/div/div/form/fieldset[2]/button")).click();
        Alert alert =  Driver.switchTo().alert();  
        String str= alert.getText();
        System.out.println(str);

    }

   }
2
  • Is it a native alert or HTML that displays a pop-up? If later, can you add the HTML source of the pop-up?
    – Barney
    Commented Jan 23, 2018 at 15:28
  • It is very difficult to get the html source of the popup...because the popup is getting vanished after 2 secs. :( Commented Jan 24, 2018 at 3:58

1 Answer 1

1

After clicking on Register insert the following code:

Note: After clicking on register button, Don't give any sleep time.

if(driver.findElement(By.cssSelector("p[class = 'notify-icon-text']").getText().equals("The email you entered already exists")){
doLogin(); //call login method with userName and password
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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