【问题标题】:ChromeDriver doesn't find Element to be clickedChromeDriver 找不到要单击的元素
【发布时间】:2019-04-01 16:07:08
【问题描述】:

Chrome - WebDriver 找不到 Instagram 登录页面的 log in 按钮。我已经尝试了 3 种方式(请参阅下面的代码),并且在所有方式中按钮都没有被点击。非常感谢任何帮助!

代码:

    System.setProperty("webdriver.chrome.driver","F:\\scraper - by 
    Url\\chromedriver.exe");

    ChromeDriver driver = new ChromeDriver();


    driver.get("https://www.instagram.com/accounts/login/?hl=en");
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.findElement(By.name("username")).sendKeys("username");
    driver.findElement(By.name("password")).sendKeys("testtest");

    //driver.findElements(By.tagName("button")).get(1).click();

    WebDriverWait wait = new WebDriverWait(driver, 10);

    WebElement button = 

wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[.='Log in']")));
    button.click();

    //driver.findElement(By.xpath("//button[.='Log in']")).click();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

【问题讨论】:

    标签: java webdriver instagram


    【解决方案1】:

    你在xpath中犯了一个小错误,你用小写字母Log ini,但是在页面上,单词是驼峰,所以你需要使用Log In

    或者

    您可以将以下 xpath 用于Login 按钮:

    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[text()='Log In']")));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-28
      • 2020-07-09
      • 2016-05-28
      • 1970-01-01
      • 1970-01-01
      • 2023-01-06
      • 2018-05-21
      • 1970-01-01
      相关资源
      最近更新 更多