Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ChromeDriver不';找不到要单击的元素_Java_Webdriver_Instagram - Fatal编程技术网

Java ChromeDriver不';找不到要单击的元素

Java ChromeDriver不';找不到要单击的元素,java,webdriver,instagram,Java,Webdriver,Instagram,Chrome-WebDriver找不到Instagram登录页面的登录按钮。我尝试了3种方式(见下面的代码),但在所有方式下按钮都没有被点击。非常感谢您的帮助 代码: System.setProperty("webdriver.chrome.driver","F:\\scraper - by Url\\chromedriver.exe"); ChromeDriver driver = new ChromeDriver(); driver.get("http

Chrome-WebDriver找不到Instagram登录页面的
登录按钮。我尝试了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);

您在xpath中犯了一个小错误,您使用了
i
of
Log-in
的小写字母,但是在页面上,单词是驼峰大小写的,因此您需要使用
Log-in

您可以将以下xpath用于
登录
按钮:

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

您在xpath中犯了一个小错误,您使用了
i
of
Log-in
的小写字母,但是在页面上,单词是驼峰大小写的,因此您需要使用
Log-in

您可以将以下xpath用于
登录
按钮:

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