我得到以下错误:
Unable to locate element:
{"method":"xpath","selector":"//*[@id='identify_email']"}
即使我写的选择器是正确的。我已经用控制台检查过了。知道如何解决这个问题吗?
package lbw;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Locators {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver",
"C:\Users\vicky\Documents\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.facebook.com");
driver.findElement(By.id("email")).sendKeys("xxxxxxx@gmail.com");
driver.findElement(By.name("pass")).sendKeys("xxxxxxxxxxx");
driver.findElement(By.linkText("Forgotten account?")).click();
driver.findElement(By.xpath("//*[@id='identify_email']")).sendKeys("xxxxxxx@gmail.com");
driver.findElement(By.xpath("//*[@value='Search']")).click();
driver.findElement(By.cssSelector("input[id='send_email']")).click(); /*im getting error in this line. Im try to select a radio. */
System.out.println("Completed");
}
}
您可以尝试添加implicity wait或WebDriver wait。下面是第二个例子:
public static void waitForElementPresent(this IWebElement element)
{
try
{
wait.Until(driver => element.Displayed);
}
catch (Exception e)
{
Assert.Fail("The element not found. The exception: n" + e.GetType());
}
}