1

我需要单击单击展开图标后打开的框后出现的。使用 Webdriver 我可以展开该框,但之后我无法单击应该打开对话框的图像图标。

该图像的 xpath 显示如下: html/body/div[2]/div/div/div/div[3]/div/div[2]/div/div[2]/div/div[2]/div/div/div/div/div/div/div/div[14]/div/div/div/div[1]/div/div[1]/div/div[2]/div/div/div/img

代码如下:

<div id="isc_X1" style="POSITION:relative;VISIBILITY:inherit;Z-INDEX:205382;CURSOR:default;" eventproxy="page$mainWindow$interactionsUI$$content$InteractionDetail$VerticalLayout1">
<div id="isc_X2" class="normal" onscroll="return page$mainWindow$interactionsUI$$content$InteractionDetail$customerInteractionSearchGrid.$lh()" style="position: absolute; left: 0px; top: 0px; width: 717px; height: 64px; z-index: 205400; margin: 0px; -moz-box-sizing: border-box; overflow: hidden;" eventproxy="page$mainWindow$interactionsUI$$content$InteractionDetail$customerInteractionSearchGrid">
<div id="isc_Y8" class="normal" onscroll="return page$mainWindow$interactionsUI$$content$InteractionDetail$MenuLayout.$lh()" style="position: absolute; left: 0px; top: 64px; width: 800px; height: 18px; z-index: 205454; padding: 0px; -moz-box-sizing: border-box; overflow: hidden; cursor: default;" eventproxy="page$mainWindow$interactionsUI$$content$InteractionDetail$MenuLayout">
<div id="isc_Y9" style="POSITION:relative;VISIBILITY:inherit;Z-INDEX:205454;CURSOR:default;" eventproxy="page$mainWindow$interactionsUI$$content$InteractionDetail$MenuLayout">
<div id="isc_YB" class="imgButton" onscroll="return page$mainWindow$interactionsUI$$content$InteractionDetail$ImageAdd.$lh()" style="position: absolute; left: 782px; top: 0px; width: 18px; height: 18px; z-index: 205472; -moz-box-sizing: border-box; overflow: hidden; cursor: pointer;" tabindex="7583" onblur="if(window.isc)isc.EH.blurFocusCanvas(page$mainWindow$interactionsUI$$content$InteractionDetail$ImageAdd,true);" onfocus="if(event.target!=this)return;isc.EH.focusInCanvas(page$mainWindow$interactionsUI$$content$InteractionDetail$ImageAdd,true);" role="button" eventproxy="page$mainWindow$interactionsUI$$content$InteractionDetail$ImageAdd">
<div id="isc_YA" style="POSITION:relative;VISIBILITY:inherit;Z-INDEX:205472;CURSOR:pointer;" eventproxy="page$mainWindow$interactionsUI$$content$InteractionDetail$ImageAdd">
<img border="0" align="TEXTTOP" height="18" width="18" suppress="TRUE" name="isc_YApage$mainWindow$interactionsUI$$content$InteractionDetail$ImageAdd" src="http://kolcaresuse01:12345/cwf/r/orga_pics/add_icon.gif?v=1371640285409en-xx"/>

请帮助解决这个问题。

4

2 回答 2

1
  1. 尽可能使用较短的定位器,//tag[@attribute_name='attribute_value']例如
  2. 您需要使用显式和隐式等待。他们在这里描述

如果我正确理解您的代码,<img>则标记为 in <div id="isc_YA" style="POSITION:relative;VISIBILITY:inherit;Z-INDEX:205472;CURSOR:pointer;" eventproxy="page$mainWindow$interactionsUI$$content$InteractionDetail$ImageAdd">。所以这是python示例:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait

## Here you're expanding the box, then:

WebDriverWait(driver, 5).until(lambda driver : driver.find_element_by_xpath("//div[contains (@id, 'constant_part_of_id')]/img").is_displayed(), "No icon displayed")
## 5 is for 5 seconds to wait
## driver is for instance of webdriver
## check the locator, it might be wrong
driver.find_element_by_xpath("//div[contains (@id, 'constant_part_of_id')]/img").click()
## Or whatever you're going to do with that
于 2013-07-01T12:35:22.440 回答
0

我会使用FluentWait而不是 WebDriverWait,因为听起来您可能会遇到需要处理/忽略的异常,直到元素准备好执行。此外,@AlexanderPetrovich 是正确的,您应该使用缩短的定位器或者可能是 css 定位器。另外,我会使用 Firefox 插件“FirePath”来验证您的定位器语法。

于 2013-07-01T14:54:10.610 回答