简体   繁体   English

使用 Selenium 和 Java 时无法定位元素:{“method”:“xpath”,“selector”:“//li[@id=”tablist1-tab3“]”} 错误

[英]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.

相关问题 Selenium WebDriver:Java:NoSuchElementException:无法找到元素:{“ method”:“ xpath”,“ selector”:“ // div [@ id ='manage_area'] / ul / li / div [2]”} - Selenium WebDriver: Java: NoSuchElementException: Unable to locate element: {“method”:“xpath”,“selector”:“//div[@id='manage_area']/ul/li/div[2]”} 无法在Selenium-java中使用XPath错误找到元素 - Unable to locate an element using xpath error in selenium-java Selenium Java 无法使用 xpath 定位元素 - Selenium Java unable to locate element using xpath Selenium:NoSuchElementException:无法找到元素 - 方法:xpath - Selenium: NoSuchElementException: Unable to locate element - method:xpath 无法找到元素:{“方法”:“ id”,“选择器”:“ sysPublishDateDate”} - Unable to locate element: {“method”:“id”,“selector”:“sysPublishDateDate”} 无法使用xpath在Selenium Webdriver中定位元素 - Unable to locate element in Selenium Webdriver using xpath 无法在Selenium中找到元素尝试过的xpath,name,id,css选择器 - Not able to locate element in Selenium tried xpath,name,id,css selector 线程“ main”中的异常org.openqa.selenium.NoSuchElementException:无此类元素:无法找到元素:{“ method”:“ id”,“ selector”:“ name”} - Exception in thread “main” org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {“method”:“id”,“selector”:“name”} 消息“org.openqa.selenium.InvalidSelectorException:无效的选择器:无法使用sendKeys找到具有XPath表达式的元素” - Message “org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the XPath expression” using sendKeys Selenium Java Webdriver,NoSuchElementException:没有这样的元素:无法找到元素:{“ method”:“类名”,“ selector”:“ btn_content”} - Selenium Java Webdriver, NoSuchElementException: no such element: Unable to locate element: {“method”:“class name”,“selector”:“btn_content”}
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM