我的硒不会打开网址只需打开火狐
问题描述:
您好。我一直都建立一个脚本登录到Gmail,但它不会键入之后我进入了电子邮件我的硒不会打开网址只需打开火狐
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.chrome.driver", "E:\\Download\\chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2&emr=1&osid=1#identifier");
Thread.sleep(4000);
WebElement myElement = driver.findElement(By.id("Email"));
myElement.sendKeys("[email protected]");
driver.findElement(By.id("next")).click();
Thread.sleep(2000);
driver.findElement(By.id("Passwd"));
myElement.sendKeys("testing");
driver.findElement(By.id("signIn")).click();
}
谁能帮我这个代码的密码?
答
试试这个
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.chrome.driver", "E:\\Download\\chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2&emr=1&osid=1#identifier");
Thread.sleep(4000);
WebElement myElement = driver.findElement(By.id("Email"));
myElement.sendKeys("[email protected]");
driver.findElement(By.id("next")).click();
Thread.sleep(2000);
WebElement myPassword = driver.findElement(By.id("Passwd"));
myPassword.sendKeys("testing");
driver.findElement(By.id("signIn")).click();
}
+0
谢谢你的作品,你可以告诉我为什么我们应该把这个代码publicWebElement myPassword = driver.findElement(By.id(“Passwd”)); –
+0
'myElement'变量指的是电子邮件测试框,您没有将密码测试框分配给'myElement',但使用相同的。如果你使用'myElement = driver.findElement(By.id(“Passwd”));'你的代码将起作用。接受答案,因为它的作品。谢谢 –
如何Firefox是越来越开?您已向Chrome发送代码。运行代码时是否收到异常? –