如何如图所示定位元素

问题描述 投票:1回答:1

该下拉列表已由值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>

图像:

“

java selenium xpath css-selectors webdriverwait
1个回答
0
投票

所需的元素是启用了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')]")));
    
© www.soinside.com 2019 - 2024. All rights reserved.