下拉列表已由值1选择,并且未通过ID或名称定位。如何找到用于图像定位的xpath?

HTML:

<select name="ctl05$ddlSelectBox" onchange="javascript:setTimeout(&#39;__doPostBack(\&#39;ctl05$ddlSelectBox\&#39;,\&#39;\&#39;)&#39;, 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')]")));

10-08 13:29