[英]Unable to locate element: {“method”:“xpath”,“selector”:“//li[@id=”tablist1-tab3“]”} error using Selenium and Java
I have received this error for several times:我多次收到此错误:
Unable to locate element: {"method":"xpath","selector":"//li[@id="tablist1-tab3"]"}
Code that I have used is:我使用的代码是:
options.addArguments("--headless");
options.addArguments("window-size=1200x900");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
WebElement tab = driver.findElement(By.xpath("//li[@id=\"tablist1-tab3\"]"));
tab.click();
Can someone help me with this error?有人可以帮我解决这个错误吗?
You need to use WebDriverWait for the elementToBeClickable()
and you can use either of the following Locator Strategies :您需要对elementToBeClickable()
使用WebDriverWait并且可以使用以下任一Locator Strategies :
cssSelector
: cssSelector
:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("li#tablist1-tab3"))).click();
xpath
: xpath
:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//li[@id=\"tablist1-tab3\"]"))).click();
WebElement tab = driver.findElement(By.xpath('//li[@id="tablist1-tab3"]')); WebElement tab = driver.findElement(By.xpath('//li[@id="tablist1-tab3"]')); try this尝试这个
Make sure the element is not inside an iFrame.确保该元素不在 iFrame 内。 If it is, then you need to first find the iFrame element and use Selenium's switchTo().如果是,那么您需要首先找到 iFrame 元素并使用 Selenium 的 switchTo()。 After that you will be able to locate elements inside the iframe.之后,您将能够在 iframe 中找到元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.