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.
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);
}
}