我有web page我希望自动化此页面,但是当我点击“登录”按钮时,它会提示我一个错误:
无法找到元素:{“method”:“link text”,“selector”:“登录”}
请说明我在哪里错了?
project.java
package com.saas.test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import com.saas.test.Configuration_file;
public class Test_1 extends Configuration_file {
public static void main(String[] args) {
// TODO Auto-generated method stub
Configuration_file var = new Configuration_file();
WebDriver firefox_dri = new FirefoxDriver();
firefox_dri.get("https://testvfgroup.appdirect.com/home");
firefox_dri.findElement(By.linkText("Log In")).click();
//firefox_dri.findElement(By.cssSelector("a.adb-primary_nav--link")).click();
//firefox_dri.findElement(By.linkText("Sign Up")).click();
}
}
答案 0 :(得分:1)
尝试使用显式等待。它会加快执行速度。
WebDriver firefox_dri = new FirefoxDriver();
wait = new WebDriverWait(firefox_dri , 120);
firefox_dri.get("https://testvfgroup.appdirect.com/home");
wait.until(ExpectedConditions.presenceOfElementLocated(By.linkText("Log In")));
firefox_dri.findElement(By.linkText("Log In")).click();
firefox_dri.findElement(By.cssSelector("a.adb-primary_nav--link")).click();
firefox_dri.findElement(By.linkText("Sign Up")).click();
答案 1 :(得分:0)
代码没有问题。只是,你试图在它完全加载页面之前找到一个元素。尝试在get
&之间提供一些implicitlyWait。 find
来电。{/ p>
WebDriver firefox_dri = new FirefoxDriver();
firefox_dri.get("https://testvfgroup.appdirect.com/home");
firefox_dri.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
firefox_dri.findElement(By.linkText("Log In")).click();