线程“main”org.openqa.selenium.InvalidSelectorException中的异常

时间:2015-04-10 12:04:35

标签: java selenium xpath

尝试选择一个Menulink我尝试通过各种选项,如通过Linktext,Xpath,但它显示无法找到这样的元素。 HTML表达式是:

<div class="bd">
  <ul class="first-of-type"> 
    <li class="yuimenubaritem clsmenubaritem yuimenubarItem-has submenu first-of-type" id="MenubarItem_new1428659607679" groupindex="0" index="0"> <a href="javascript :void(0);" class="yuimenubaritemlabel yuimenubaritemlabel-hassubmenu">New</a></li>
  </ul>
</div>  

我厌倦了所有可能的选择

1)

    WebElement menulink = wd.findElement(By.xpath("//* [@id='MenuBarItem_new1428659607679']"));
    Actions action= new Actions(wd);
    action.moveToElement(menulink).build().perform();
    Thread.sleep(5000L);

2)

    WebElement menulink=wd.findElement(By.linkText("New"));`

3)

    WebElement menulink=wd.findElement(By.xpath("//ul[contains(@class,'first of type')]and //li[contains(@id,'MenuBarItem_new1428643471800') ] "));
    menulink.findElement(By.tagName("a")).click();
    menulink.click();

1 个答案:

答案 0 :(得分:0)

driver.findElement(By.cssSelector("div.bd li.submenu a")).click();