ChromeDriver 找不到要单击的元素
ChromeDriver doesn't find Element to be clicked
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);
你在xpath中犯了一个小错误,你在小写字母中使用了i
of Log in
,但是在页面上,单词是驼峰式的,所以你需要使用Log In
或
您可以为 Login
按钮使用以下 xpath:
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[text()='Log In']")));
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);
你在xpath中犯了一个小错误,你在小写字母中使用了i
of Log in
,但是在页面上,单词是驼峰式的,所以你需要使用Log In
或
您可以为 Login
按钮使用以下 xpath:
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[text()='Log In']")));