How do I handle the login pop up window using Selenium Webdriver 4.0 beta? Here's my scenario:
PS: I have tried the different solutions offered in previous similar questions but nothing seems to work for me. Code below (I am quite new to Selenium testing so any pointers will be appreciated).
public class LoginTest {
public static void main(String[] args){
//Setting the driver path
System.setProperty("webdriver.chrome.driver", "C:\\path");
//Creating WebDriver instance
WebDriver driver = new ChromeDriver();
//Navigate to web page
driver.get("https://url");
//Maximising window
driver.manage().window().maximize();
//Locating web element
WebElement username = driver.findElement(By.id("email"));
WebElement password = driver.findElement(By.name("password"));
WebElement login = driver.findElement(By.name("submit"));
//Performing actions on web elements
username.sendKeys("email");
password.sendKeys("password");
login.click();
//Closing browser session
driver.quit();
}
}
Then you should give it a try using explicitWait
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new ChromeDriver();
//Navigate to web page
driver.get("https://url");
//Maximising window
driver.manage().window().maximize();
//Locating web element and performing the action
new WebDriverWait(driver,10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("email"))).sendKeys("");
new WebDriverWait(driver,10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("password"))).sendKeys("");
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("submit"))).click();
//Closing browser session
driver.quit();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.