Hi I am trying to automate https://www.nextgenerationautomation.com and unable to click on login / SignUp button using Selenium 4
Steps:
- Navigate to URL: https://www.nextgenerationautomation.com
- Click on LogIn/SignUp button.
Issue: when I am using Thread.Sleep, code is working fine but when I am using explicit wait & implicit wait it's not working.
I have added Implicit in my base class at the time of driver initialization.
Here is the code that I have tried.
public class nextGenAutomationLoginPage extends Base {
@FindBy(xpath = "(//button[@class='_1YW_5'])[1]")
WebElement login;
public nextGenAutomationLoginPage() {
super();
PageFactory.initElements(driver, this);
// TODO Auto-generated constructor stub
}
public void clickOnLogin() throws InterruptedException {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
System.out.println(driver.getTitle());
// Thread.sleep(2000);
wait.until(ExpectedConditions.elementToBeClickable(login));
//wait.until(ExpectedConditions.presenceOfNestedElementLocatedBy(login, By.xpath("//div[@class='_10b1I']") ));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0,document.body.scrollHeight)");
js.executeScript("arguments[0].scrollIntoView();", login);
login.click();
//driver.findElement(By.xpath("(//button[@class='_1YW_5'])[1]")).click();
wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//div[@id='comp-kaoxkn4a1']")));
String sign = driver.findElement(By.xpath("//div[@id='comp-kaoxkn4a1']/h1/span")).getText();
System.out.println(sign);
}
Note: I tried to add Scroll as well to add some wait before clicking.
