import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
public class SeleniumBasics {
public static void main(String[] args) {
WebDriver driver= new ChromeDriver();
driver.get("https://formy-project.herokuapp.com/");
driver.manage().window().maximize();
driver.findElement(By.xpath("//body/div[1]/div[1]/li[1]")).click();
}
}
我正在尝试单击此页面https://formy-project.herokuapp.com/中的元素“自动完成” ...不起作用..请帮忙吗?
绝对 Xpath 相对 Xpath 按元素查找
您可以使用 text() 函数来查找元素,而不是使用绝对 xpath。
//a[text()='Autocomplete']
您正在定位
<li>
元素。您应该定位<a>
元素。也不要使用绝对 XPath。使用相对 XPath,如下所示。