我正在尝试在www.wordpress.com 上自动化登录过程
- 步骤1:点击";登录";右上角的按钮
- 步骤2:点击";继续使用谷歌";在登录页面上
但我只能执行步骤1。当我自动点击";继续使用Google";,它就是不响。
所发生的是光标一直在闪烁;电子邮件地址或用户名";领域它只是没有点击其他任何东西。如果我尝试自动化也是如此。这是什么iframe问题吗?请帮助
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class TestAddNewPost {
String baseUrl = "https://wordpress.com/";
public void LoginIntoWordpress(){
// System.setProperty("webdriver.chrome.driver", "/home/ashwin/Desktop/chromedriver");
System.setProperty("webdriver.gecko.driver", "/home/ashwin/Desktop/geckodriver");
// WebDriver driver = new ChromeDriver();
WebDriver driver = new FirefoxDriver();
driver.get(baseUrl);
WebElement LoginButton = driver.findElement(By.xpath("//a[@class='x-nav-link x-link'] [contains(text(),'Log In')]"));
LoginButton.click();
WebElement continueWithGoogle = driver.findElement(By.xpath("//span[contains(text(),'Continue with Google')]"));
try {
Thread.sleep(2000);
} catch(InterruptedException ex) {
ex.printStackTrace();
}
continueWithGoogle.click();
}
public static void main(String[] args){
TestAddNewPost object = new TestAddNewPost();
object.LoginIntoWordpress();
}
}
您只需要提供更多的等待时间,然后单击"继续使用谷歌"按钮
driver.get("https://www.wordpress.com");
WebElement LoginButton = driver.findElement(By.xpath("//a[@class='x-nav-link
xlink'[contains(text(),'LogIn')]"));
LoginButton.click();
driver = new ChromeDriver();
driver.navigate().to("https://www.wordpress.com");
WebElement LoginButton = driver
.findElement(By.xpath("//a[@class='x-nav-link x-link'][contains(text(),'Log In')]"));
LoginButton.click();
Thread.sleep(5000);
WebElement continueWithGoogle =
driver.findElement(By.xpath("//span[contains(text(),'Continue with Google')]"));
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
continueWithGoogle.click();
}
Hope the above code solves you issue