首页 文章

ElementNotVisibleException:元素当前不可见,因此可能无法与之交互

提问于
浏览
0

我收到了 ElementNotVisibileException 但是这个页面没有名称为"History"的重复名称,但它确实有"Calls History" . 任何人都可以建议最好的定位器来定位元素?

<li class="ui-widget ui-menuitem ui-corner-all ui-menu-parent" aria- haspopup="true" role="menuitem">
   <a class="ui-menuitem-link ui-corner-all" href="javascript:void(0)">
      <span class="ui-menuitem-text">History</span>
      <span class="ui-icon ui-icon-triangle-1-e"></span>
   </a>

错误

org.openqa.selenium.ElementNotVisibleException:元素当前不可见,因此可能无法与之交互(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:122毫秒生成信息:版本:'2.52.0',修订:'4c2593c',时间:'2016-02-11 19:03:33'系统信息:主持人:'rsn-GA-78LMT-S2',ip:'127.0.1.1',os.name:'Linux' ,os.arch:'amd64',os.version:'3.13.0-54-generic',java.version:'1.7.0_101'Session ID:17716ecc-ffe3-40f9-92a6-8a106acf478dDriver info:org.openqa . selenium.firefox.FirefoxDriver Capabilities [{platform = LINUX,acceptSslCerts = true,javascriptEnabled = true,cssSelectorsEnabled = true,databaseEnabled = true,browserName = firefox,handlesAlerts = true,nativeEvents = false,webStorageEnabled = true,rotating = false,locationContextEnabled = true,pplicationCacheEnabled = true,takesScreenshot = true,version = 38.0.1}] atun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

1 回答

  • 0

    如果你想获得具有文本 Historya 元素,请尝试使用 linkTextExpectedConditions.visibilityOfElementLocated 等待元素可见,如下所示: -

    WebDriverWait wait = new WebDriverWait(driver, 10);
    WebElement linkElement= wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("History")));
    

    或者如果你想获得 span 元素,其中包含 History 文本,请尝试使用 xPath ,如下所示: -

    WebDriverWait wait = new WebDriverWait(driver, 10);
    WebElement spanElement = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[text() = 'History']")));
    

    Edited : - 如果使用鼠标悬停事件可以看到 element ,请尝试使用 Action 执行 MouseOver ,如下所示: -

    WebDriverWait wait = new WebDriverWait(driver, 10);
    WebElement spanElement = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//span[text() = 'History']")));
    Actions builder = new Actions(driver);    
    builder.moveToElement(spanElement).perform();
    

    要么

    builder.mouse.mouseMove(((Locatable)spanElement).coordinates)
    

    希望它能工作.. :)

相关问题