亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從硒的下拉列表中選擇選項

如何從硒的下拉列表中選擇選項

小怪獸愛吃肉 2023-07-19 16:28:02
如何在 Selenium 中單擊每個選項。<div class="el-select-dropdown__wrap el-scrollbar__wrap" style="margin-bottom: -17px; margin-right: -17px;" xpath="1">  <ul class="el-scrollbar__view el-select-dropdown__list">  <!---->    <li class="el-select-dropdown__item selected hover" style="">      <span>Part number</span>    </li>    <li class="el-select-dropdown__item">      <span>Work order number</span>    </li>  </ul></div>我嘗試通過 Actions 類、Select 類沒有效果。當我單擊列表時可見,但我無法找到該元素。硒看不到它。
查看完整描述

3 回答

?
天涯盡頭無女友

TA貢獻1831條經驗 獲得超9個贊

Work order number從dropdown“誘導”WebDriverWait和“跟隨”xpath 選項中進行選擇elementToBeClickable。


WebDriverWait wait = new WebDriverWait(driver, 30);

WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='el-select-dropdown__wrap el-scrollbar__wrap']/ul[@class='el-scrollbar__view el-select-dropdown__list']//li[./span[text()='Work order number']]")));

element.click()

或者


WebDriverWait wait = new WebDriverWait(driver, 30);

WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='el-select-dropdown__wrap el-scrollbar__wrap']/ul[@class='el-scrollbar__view el-select-dropdown__list']//li//span[text()='Work order number']")));

element.click()


查看完整回答
反對 回復 2023-07-19
?
繁星淼淼

TA貢獻1775條經驗 獲得超11個贊

使用以下代碼:


WebDriverWait wait = new WebDriverWait(driver, 30);

WebElement dropdown = driver.findElement(By.xpath(".//ul[starts-with(@class,'el-scrollbar__view')]"));    

List<WebElement> options = driver.findElements(By.xpath(".//li[starts-with(@class,'el-select-dropdown__item')]"));


public void selectOption(String option){

    wait.until(ExpectedConditions.elementToBeClickable(dropdown));

    dropdown.click();

    wait.until(ExpectedConditions.visibilityOfAllElements(options));

    for(WebElement element : options){

         if(element.getText().equals(option))

              element.click();

    }

}


查看完整回答
反對 回復 2023-07-19
?
Smart貓小萌

TA貢獻1911條經驗 獲得超7個贊

使用下面的代碼。


    WebDriverWait wait = new WebDriverWait(driver, 30);

    WebElement dropdown = driver.findElement(By.xpath(".//ul[starts-with(@class,'el-scrollbar__view')]"));

    List<WebElement> options = driver.findElements(By.xpath(".//li[starts-with(@class,'el-select-dropdown__item')]"));


    @Test

    public void testCase1() {

        wait.until(ExpectedConditions.elementToBeClickable(dropdown));

        dropdown.click();

        wait.until(ExpectedConditions.visibilityOfAllElements(options));

        for (WebElement element : options) {

            element.click();

        }

    }


查看完整回答
反對 回復 2023-07-19
  • 3 回答
  • 0 關注
  • 195 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號