selenium
  • xpath
  • selenium-webdriver
  • 2015-04-21 47 views 0 likes 
    0

    我必须点击应用程序中的关闭按钮。所以,我试图用xpath来标识元素,但是我最终得到的元素不是可见的异常。所以,我只是用Thread.sleep(5000)并没有抛出No Such Element exception然后无法使用xpath识别webelement

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//img[@src='https://healthhomestg.gsihealth.com:6161/dashboard/dashboardapp/sc/skins/EnterpriseBlue/images/headerIcons/close.png']"))); 
    

    但我仍然结束了No such element exception。然后,在div标签中的id和img标签中的名称会为每个页面加载动态更改。请帮我在确定的关闭按钮,并点击它,我用

    的XPath:

    "//img[@src='https://healthhomestg.gsihealth.com:6161/dashboard/dashboardapp/sc/skins/EnterpriseBlue/images/headerIcons/close.png']" 
    

    关闭按钮代码片段下面给出

    <div id="isc_9L" class="imgButton" role="button" onscroll="return isc_ManageCareTeamWindow_0_closeButton.$lh()" style="position: absolute; left: 1057px; top: 2px; width: 15px; height: 15px; z-index: 202052; overflow: hidden; box-sizing: border-box; cursor: pointer; display: inline-block;" eventproxy="isc_ManageCareTeamWindow_0_closeButton"> 
    
    <img width="15" height="15" border="0" align="TEXTTOP" draggable="true" suppress="TRUE" name="isc_9Lmain" src="https://healthhomestg.gsihealth.com:6161/dashboard/dashboardapp/sc/skins/EnterpriseBlue/images/headerIcons/close.png"> 
    
    </div> 
    

    回答

    1
    driver.findElement(By.cssSelector("img[src*='close.png']")); 
    

    所以,在这里我们通过cssSelector来识别元素IMG,它具有可以包含“close.png”的src属性。

    +0

    我评论过它。 – stanjer

    +0

    谢谢,Stanjer。我尝试了您提供的代码,但没有发生点击操作。要强调的是,被测试的应用程序是使用GWT开发的,我想user-extensions.js和user-extensions-ide.js必须使用IDE或Selenium RC进行配置,但我应该在webdriver(硒) –

    0

    试试这个:

    //img[contains(@src,'headerIcons/close.png')] 
    
    +0

    谢谢,阿迪亚。我在xpath中尝试了它,并没有执行点击操作,并且最终发生了以下错误,尽管我使用了Thread.sleep(),隐式和WebDriverWait。该应用程序已使用GWT开发,我猜user-extensions.js和user-extensions-ide.js必须用IDE或Selenium RC进行配置,但我不知道如何使用webdriver执行它 线程“main” org.openqa.selenium.ElementNotVisibleException:元素当前不可见,因此可能不会与 –

    相关问题