I have been experimenting with some simple Automation scripts using Java and Selenium, but with this login script I am running into an issue where the web elements are not being found by my automation script. The code below is my current login automation script, and for obvious reasons the website, username, and password are removed from the code...
Note: I am not too familiar with using Selenium and Java so any advice would go a long way...
import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.opera.OperaDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class Login { public static void main(String[] args) throws InterruptedException { // TODO Auto-generated method stub Login obj = new Login(); obj.LoginScriptTest(); } public void LoginScriptTest() throws InterruptedException { String curDir = System.getProperty("user.dir"); System.setProperty("webdriver.chrome.driver", curDir+"\\drivers\\chromedriverexe.exe"); ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("excludeSwitches", new String[]{"enable-automation"}); WebDriver driver = new ChromeDriver(options); driver.get("https://********.com"); driver.findElement(By.xpath("//span[@class='myTestSpan']")).click(); driver.findElement(By.xpath("//div[@class='myTestDiv']")).click(); WebDriverWait wait3 = new WebDriverWait(driver, 4); wait3.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//form[@method='post']"))); WebElement userName = driver.findElement(By.id("username")); WebElement password = driver.findElement(By.id("password")); String username = "********@yahoo.com"; String pwd = "*******"; for (int i = 0; i < username.length(); i++) { char c = username.charAt(i); String s = new StringBuilder().append(c).toString(); userName.sendKeys(s); } for (int i = 0; i < pwd.length(); i++) { char c = pwd.charAt(i); String s = new StringBuilder().append(c).toString(); password.sendKeys(s); } WebElement ele = driver.findElement(By.id("login")); ele.sendKeys(Keys.ENTER); } }