【问题标题】:passwordNext button click for Gmail密码下一步按钮单击 Gmail
【发布时间】:2018-04-14 22:35:09
【问题描述】:

gmail 的 passwordNext 按钮并不总是有效。显式等待似乎也无济于事。

public void funcLogin() {      
    driver.findElement(LoginMail).sendKeys(prop.getProperty("email"));
    driver.findElement(LoginMail).sendKeys(Keys.RETURN);
    driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
    driver.findElement(PwdMail).sendKeys(prop.getProperty("passwd"));
    driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
    driver.findElement(By.id("passwordNext")).click();
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}    

错误:

org.openqa.selenium.WebDriverException: unknown error: Element <div role="button" id="passwordNext" class="O0WRkf zZhnYe e3Duub C0oVfc nDKKZc DL0QTb" jscontroller="VXdfxd" jsaction="click:cOuCgd; mousedown:UX7yZ; mouseup:lbsD7e; mouseenter:tfO1Yc; mouseleave:JywGue;touchstart:p6p2H; touchmove:FwuNnf; touchend:yfqBxc(preventMouseEvents=true|preventDefault=true); touchcancel:JMtRjd;focus:AHmuwe; blur:O22p3e; contextmenu:mg9Pef;" jsshadow="" jsname="Njthtb" aria-disabled="false" tabindex="0">...</div> is not clickable at point (787, 340). Other element would receive the click: <div class="ANuIbb IdAqtf" jsname="k4HEge" tabindex="0"></div>

【问题讨论】:

  • 你不必每次都重写隐式等待,一旦写好它就会应用到你调用findElement方法的任何人
  • 你在哪里写了显式等待的代码?

标签: java selenium selenium-webdriver gmail


【解决方案1】:

您必须正确使用显式等待才能使用该功能:
这是 Gmail 登录的代码,运行良好:

代码

public class QQ_TT {

    static WebDriver driver;
    static WebDriverWait wait;

    public static void main(String[] args) throws InterruptedException {
            System.setProperty("webdriver.chrome.driver", "D:\\Automation\\chromedriver.exe");
            driver = new ChromeDriver();
            wait = new WebDriverWait(driver,50); 
            driver.manage().window().maximize();    
            driver.get("https://www.gmail.com");
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
            wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("headingText"))));
            driver.findElement(By.id("identifierId")).sendKeys("QQ_TT@gmail.com");
            driver.findElement(By.xpath("//span[text()='Next']")).click();
            wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("headingText"))));
            driver.findElement(By.name("password")).sendKeys("qq_tt@stackoverflow");
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[text()='Next']")));
            wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='Next']")));
            driver.findElement(By.xpath("//span[text()='Next']")).click();

        }

    }

如果您对此有任何疑虑,请告诉我。

【讨论】:

  • 很高兴!我可以帮忙!
猜你喜欢
  • 1970-01-01
  • 2018-11-04
  • 1970-01-01
  • 2023-03-26
  • 1970-01-01
  • 2018-06-13
  • 1970-01-01
  • 2021-05-08
  • 1970-01-01
相关资源
最近更新 更多