After answers given by Anand and Prophet, I made the changes in the code but now it is not validating the test results whether the account got created or not. Ideally, it should validate whether after giving all the required information account got created or not. I am not sure where it went wrong please help me on the same.
package Seleniumtesting;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Selenium {
ChromeDriver driver;
String url ="https://login.mailchimp.com/signup/";
public void invokeBrowser() {
try {
System.setProperty("webdriver.chrome.driver","C:\\Users\\hp\\Desktop\\Selenium\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
TimeUnit.SECONDS.sleep(2);
driver.get(url);
String urlFromWebpage = driver.getCurrentUrl();
if(urlFromWebpage.equals("https://login.mailchimp.com/signup/")) {
System.out.println("PASS");
}
else {
System.out.println("FAIL");
}
}
catch(InterruptedException ex)
{
ex.printStackTrace();
}
}
public void signup(){
try {
WebElement createAccountHeading = driver.findElement(By.xpath("//span[text()='Create an account or ']"));
if(createAccountHeading.isDisplayed()) {
System.out.println("PASS");
}else
System.out.println("FAIL");
driver.findElement(By.name("email")).sendKeys("[email protected]");
driver.findElement(By.name("username")).sendKeys("Testvina1243");
driver.findElement(By.name("password")).sendKeys("Test123@");
TimeUnit.SECONDS.sleep(2);
driver.findElement(By.name("marketing_newsletter")).click();
TimeUnit.SECONDS.sleep(2);
//driver.findElement(By.xpath("//button[@id='create-account']")).click();
driver.findElement(By.xpath("//*[@id=\"create-account\"]")).click();
TimeUnit.SECONDS.sleep(2);
String u = driver.getCurrentUrl();
System.out.println("URL: " u);
/*if(u.equalsIgnoreCase("https://login.mailchimp.com/signup/success/"))
{
System.out.println("PASS !! Account created successfully");
}
else
{
System.out.println("FAIL !! It might have not met the criteria");
}*/
driver.close();
}
catch(InterruptedException ex)
{
ex.printStackTrace();
}
}
public static void main(String[] args) {
Selenium mc = new Selenium();
mc.invokeBrowser();
mc.signup();
}
}
CodePudding user response:
Your password is missing a special character. The Sign Up button not appearing on that page until you filled all the fields with valid data.
So if you change your password from Test123 to f.e. Test123$ you will be able to see, locate and click the Sing Up button with this code:
driver.findElement(By.xpath("//button[@id='create-account']")).click();
CodePudding user response:
This you can use for Sign up:
driver.find_element(By. ID, "create-account").click()
The caveat is that it gets enabled only when the password criteria is met with, which for mailchimp is at least (as per the website) : 1 lower character, 1 upper character, 1 number, 1 special character, and minimum password length is 8.
I see you used your password as 'Test123' which would not enable the button, as the set criteria is not met. Please check the password rules given just below the password input box of the website.
UPDATE: Per your latest comment, I am updating here. I see that when I tested, it redirects to another page where it asks for email confirmation.
https://login.mailchimp.com/signup/success/?username=Test1243&userId=168758830&loginId=181489470
Now, there is /success/ in it. And I suppose you are using this page to assert that your act was successful; in which case, I would say that you used .equals in your code, which fails it as there is more to the url than you are looking for, so it should not be .equals, but it should something be like .contains or something like that (I do not know what Java uses, so please search for that equivalent keyword)
