How will I be able to add Sign Up button of the site https://login.mailchimp.com/signup/. I inspected but found button id but how to add this in my program as I am quite new to selenium so wondering If I can get any suggestions. Below is my code in which all fields are populating when I am running the program except the Sign Up.
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("Test1243");
driver.findElement(By.name("password")).sendKeys("Test123");
driver.findElement(By.name("marketing_newsletter")).click();
TimeUnit.SECONDS.sleep(2);
//How to add Sign Up button
}
catch(InterruptedException ex)
{
ex.printStackTrace();
}
}
public static void main(String[] args) {
Selenium mc = new Selenium();
mc.invokeBrowser();
mc.signup();
}
}
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.
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();
