使用java中的selenium webdriver登录Gmail
import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class NewGmail { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); String url = "https://accounts.google.com/signin"; driver.get(url); driver.findElement(By.id("identifierId")).sendKeys("cp8805"); //driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); WebDriverWait wait=new WebDriverWait(driver, 20); driver.findElement(By.xpath("//span[@class='RveJvd snByac']")).click(); driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS); driver.findElement(By.xpath("//input[@class='whsOnd zHQkBf']")).sendKeys("xxxxxx"); driver.findElement(By.xpath("//span[@class='RveJvd snByac']")).click(); } }
在邮件ID之后,我的密码也会写入id框选项并且服务器重定向到下一个密码页面。 我想问一下我将做什么,以便我的密码只能输入密码页面。
以下是通过一组有效凭据登录Gmail帐户的工作代码块 –
System.setProperty("webdriver.gecko.driver","C:\\your_directory\\geckodriver.exe"); WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); String url = "https://accounts.google.com/signin"; driver.get(url); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); WebElement email_phone = driver.findElement(By.xpath("//input[@id='identifierId']")); email_phone.sendKeys("your_email_phone"); driver.findElement(By.id("identifierNext")).click(); WebElement password = driver.findElement(By.xpath("//input[@name='password']")); WebDriverWait wait = new WebDriverWait(driver, 20); wait.until(ExpectedConditions.elementToBeClickable(password)); password.sendKeys("your_password"); driver.findElement(By.id("passwordNext")).click();
- 编写一个firefox插件并从java应用程序访问它
- 无法使用IEDriver单击IE上的链接
- java运行时6与socks v5代理 – 可能吗?
- 如何调试Firefox警报框自动关闭并且无法检测Serenity BDD中的警报?
- Selenium测试运行不会保存cookie?
- 如何使用Selenium webdriver和Java为firefox设置代理?
- 使用BrowserMobProxy,Selenium,Firefox,marionette / gecko获取请求和响应
- Firefox浏览器没有打开selenium webbrowser代码
- 在PATH中找不到firefox二进制文件。 确保安装了firefox。 操作系统似乎是:VISTA