Java 找不到包含Xpath的元素

Java 找不到包含Xpath的元素,java,selenium,webdriver,selenium-webdriver,Java,Selenium,Webdriver,Selenium Webdriver,我试图找出资源管理器元素的xpath,当我尝试使用此代码时, driver.findElement(By.xpath(“资源管理器xpath”))。单击(),我出现了一个错误,说找不到元素 <div class="os-titlebar navbar navbar-inverse"> <div class="navbar-inner"> <div class="container"> <ul class="nav m

我试图找出资源管理器元素的xpath,当我尝试使用此代码时,
driver.findElement(By.xpath(“资源管理器xpath”))。单击()
,我出现了一个错误,说找不到元素

<div class="os-titlebar navbar navbar-inverse">
   <div class="navbar-inner">
      <div class="container">
          <ul class="nav menu-primary os-navbar-icon">
          <ul class="nav context-menu" style="">
           <ul class="nav os-navbar-icon os-titlebar-shortcuts pull-right os_shortcuts">
                 <li class="os-navbar-icon-home selected">
                 <li class="os-navbar-icon-quicklaunch os_quick_start">
                 <li class="os-navbar-icon-resourcemanager">
                  <li class="os-navbar-icon-apptray">
                  <li class="os-navbar-icon-notifications">
                  <li class="os-navbar-icon-minimise-close">
            </ul>
<form class="navbar-search pull-right ui-os-search-form" action="">
<ul class="nav os-navbar-icon os-desktop-navigation" style="left: 407.5px;">
</div>


资源管理器xpath不是有效的xpath表达式

这应该起作用:

driver.findElement(By.xpath("//li[@class='os-navbar-icon-resourcemanager']")).click()

资源管理器xpath
不是有效的xpath表达式

这应该起作用:

driver.findElement(By.xpath("//li[@class='os-navbar-icon-resourcemanager']")).click()

使用css选择器而不是xpath。也是一个例子


使用css选择器而不是xpath。也是一个例子

您肯定只有在两种情况下才会遇到“找不到元素”

 1.The Element is yet to Load
     - Put some wait here.
 2. You may try to locate the element wrongly .
     - Double Check your Xpath/ID(what ever)
     - Make sure you are in the same frame where the element is present.If not, switch to the frame then.
您肯定只有在两种情况下才会遇到“找不到元素”

 1.The Element is yet to Load
     - Put some wait here.
 2. You may try to locate the element wrongly .
     - Double Check your Xpath/ID(what ever)
     - Make sure you are in the same frame where the element is present.If not, switch to the frame then.


感谢您的快速回复,当我使用代码时,我没有收到任何错误,但是元素没有被单击……:(@ShivaChalla,那是另一个问题。你需要等待元素出现。@ShivaChalla查看Webdriverwaital,因为这个问题回答了你的问题,所以你应该将它标记为正确并投票。似乎越来越多的人在回答问题时不接受正确的答案或投票。这非常重要糟糕的形式感谢您的快速回复,当我使用代码时,我没有收到任何错误,但是元素没有被单击……:(@ShivaChalla,那是另一个问题。你需要等待元素出现。@ShivaChalla查看Webdriverwaital,因为这个问题回答了你的问题,所以你应该将它标记为正确并投票。似乎越来越多的人在回答问题时不接受正确的答案或投票。这非常重要错误的形式更好的等待示例是等待特定元素单击on@Alp如果您注意到wait.until(),我会这样做。它会等待元素准备好单击,然后单击。更好的等待示例是等待特定元素单击on@Alp如果你注意到等待,我会的。它等待元素准备好单击,然后单击。你能提到你实际使用的xpath吗?哎呀…我没有看答案。他们一定帮了你。你能提到你实际使用的xpath吗?哎呀…我没有看答案。他们一定帮了你。