我的selenium webdriver脚本在Chrome上不起作用

时间:2016-08-02 21:38:41

标签: selenium webdriver

package javapackage;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
public class SeleniumQuora {
public static void LaunchQuora()
{
    System.setProperty("webdriver.chrome.driver","E:\\SBI SO\\Selenium\\Extracts\\chromedriver.exe");
    WebDriver driver=new ChromeDriver();
    driver.get("https://www.quora.com/");
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(13, TimeUnit.SECONDS);
    driver.findElement(By.xpath("//*[@id='__w2_lIh8Ilg_google_connect_button']/span")).click();

    }

public static void main(String[] args) {
    LaunchQuora();}}

此代码应该在signIn页面中单击“继续使用Google”选项。但没有任何反应。它非常基本我知道,但我搜索了大多数地方,无法找到答案。

1 个答案:

答案 0 :(得分:0)

实际上你找到了错误的元素,在这个website中没有我看到的id为__w2_lIh8Ilg_google_connect_button的元素,可以提供id是动态生成的,所以如果你想点击{{ 1}}按钮只需尝试使用Continue with Google,如下所示: -

By.linkText()

希望它有所帮助.. :)