该下拉列表已由值1选择,并且未通过ID或名称定位。如何找到用于图像定位的xpath?
HTML:
<select name="ctl05$ddlSelectBox" onchange="javascript:setTimeout('__doPostBack(\'ctl05$ddlSelectBox\',\'\')', 0)" id="ctl05_ddlSelectBox" style="height:21px;width:180px;">
<option selected="selected" value="-1">--Select Box--</option>
<option value="2742">Box_H026_01</option>
图像:
所需的元素是启用了JavaScript的<select>
节点。因此,找到必须为visibilityOfElementLocated()
引入WebDriverWait的元素,然后可以使用以下解决方案之一:
使用CSS_SELECTOR
:
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("select[name$='ddlSelectBox'][onchange*='ddlSelectBox']")));
使用XPATH
:
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//select[contains(@name, 'ddlSelectBox') and contains(@onchange, 'ddlSelectBox')]")));