【问题标题】:movehover from Selenium on a dropdown在下拉菜单中从 Selenium 移动
【发布时间】:2017-09-02 07:38:34
【问题描述】:

以下是 HTML 中的代码

<div id="pMenu_root_10" class="itemBorder" style="position: absolute; left: 809px; top: 0px; width: 58px; height: 98px; z-index: 1000; background: rgb(190, 213, 231) none repeat scroll 0% 0%; cursor: default;" onmouseover="pMenu.over('root',10)" onmouseout="pMenu.out('root',10)" onclick="pMenu.click('root',10)">
   <div class="lowText" style="font-size: 11px; FONT-FAMILY: Arial; color: #0066CC; position: absolute; left: 1px; top: 1px; width: 56px; height: 96px">Reports</div>
</div>

我正在尝试将鼠标从 selenium 悬停到,以便我可以选择存在的子菜单之一。但是我的硒无法获取元素

WebElement ele = driver.findElement(By.xpath(".//div[@id='pMenu_root_10']/div[text()='Reports']"));     
Actions act = new Actions(driver);
act.moveToElement(ele).perform();

我尝试使用 Firepath 提供的绝对 Xpath

.//*@id='loginFormName']/table[2]/tbody/tr/td[2]/table[1]/tbody/tr[5]/td/div/table/tbody/tr/td[3]/img

请帮我找出问题

下面是返回的错误

Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":".//div[@id='pMenu_root_10']/div[text()='Reports']"}

【问题讨论】:

  • 仍然报同样的错误。它仍然没有得到 pMenu_root_10
  • 请传递错误,您能分享您的网站网址吗?
  • 这是公司网站,有登录凭证,所以不能分享。如果你愿意,我可以在线程“main”org.openqa.selenium.NoSuchElementException 中传递 html 代码异常:没有这样的元素:无法找到元素:{“method”:“xpath”,“selector”:“。//* [@id='pMenu_root_10']/div"}
  • 请注意,当我尝试通过 ff 中的 xpath 搜索标签时,我能够找到这个元素

标签: jquery html css selenium


【解决方案1】:

在网站上输入用户名密码后,使用下面提到的代码访问子菜单。

driver.findElement(By.id("login_button")).click();

WebDriverWait after_login = new WebDriverWait(driver, 10);   
after_login.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//div[@id='parent_25']/a[contains(text(), 'Projects, Delivery & Sales')]"))));

WebElement menu_element = driver.findElement(By.xpath("//div[@id='parent_25']/a[contains(text(), 'Projects, Delivery & Sales')]"));
menu_element.click();

WebDriverWait wait = new WebDriverWait(driver, 10);   
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//div[@id='parentGroup_25']/..//div[@class='hreftheme_AppLinks_sub_links_Li_Megamenu']/a[contains(text(), 'Integrated Project Management System')]"))));

WebElement sub_menu_element = driver.findElement(By.xpath("//div[@id='parentGroup_25']/..//div[@class='hreftheme_AppLinks_sub_links_Li_Megamenu']/a[contains(text(), 'Integrated Project Management System')]"));
sub_menu_element.click();

WebDriverWait IPMS_sub_menu_launch_button = new WebDriverWait(driver, 10);   
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//div[@id='content']/..//following::td/img[@alt='Launch IPMS']"))));

driver.findElement(By.xpath("//div[@id='content']/..//following::td/img[@alt='Launch IPMS']")).click();
Thread.sleep(8000);

String childWindow = (String) driver.getWindowHandles().toArray()[1];  
driver.switchTo().window(childWindow);   // Switch to newly opened window. 
System.out.println("Switch to new tab.");

driver.findElement(By.xpath("//form[@id='loginFormName']/..//following::td/img[@src='images/go_on.gif']")).click(); // After New tab, Webelement is easily accessible.
Thread.sleep(8000);

   try
   {
      String report_page_url = driver.getCurrentUrl();
      System.out.println(report_page_url);

      String url = "https://ipmsapp.ultimatix.net/webipms/calhome_new.jsp";

      if(report_page_url.equals(url))
      {
          System.out.println("I am on the report page.");
      }
   }
   catch(Exception e)
   {
       System.out.println("Report page not open.");
   }

【讨论】:

    猜你喜欢
    • 2020-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-25
    • 2019-03-26
    • 1970-01-01
    相关资源
    最近更新 更多