无法使用xpath识别webelement

时间:2015-04-21 09:33:39

标签: selenium xpath selenium-webdriver

我必须单击应用程序中的关闭按钮。所以,我尝试使用xpath识别元素,但我最终得到的元素是不可见的异常。所以,我刚刚使用了Thread.sleep(5000),它确实抛出了No Such Element exception然后

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>

2 个答案:

答案 0 :(得分:1)

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

所以,这里我们通过cssSelector识别元素IMG,其中src属性可以包含&#34; close.png&#34;。

答案 1 :(得分:0)

试试这个:

 //img[contains(@src,'headerIcons/close.png')]
相关问题