3 回答

TA貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超6個(gè)贊
下拉是使用選擇和選項(xiàng)標(biāo)簽進(jìn)行的。您可以使用 selenium 中的 select 類。
Select dropdown = new Select(driver.findElement(By.cssSelector("select.form-control.input-sm")))
dropdown.selectByVisibleText("Primary-Secondary (1:Many)");
或使用 value 屬性。
dropdown.selectByValue("PRIMARY-SECONDARY");
編輯:
您可以嘗試使用此代碼:
Select dropdown = new Select(new WebDriverWait(driver,10).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("select.form-control.input-sm"))));
dropdown.selectByVisibleText("Primary-Secondary (1:Many)");

TA貢獻(xiàn)1951條經(jīng)驗(yàn) 獲得超3個(gè)贊
已經(jīng)提到了很多方法,您可以使用不同的方法,例如
WebElement dropdownEle = driver.findElement(By.xpath("//select[@class='form-control input-sm']"));
Select Dropdown = new Select(dropdownEle);
Dropdown.selectByIndex(1);
//Dropdown.selectByValue("Parent-Child (1:Many)");
//Dropdown.selectByValue("Primary-Secondary (1:Many)");
您可以使用selectByIndex(index)orselectByValue(value)或selectByVisibleText(text),但最好的使用方式是使用selectByValue(value)

TA貢獻(xiàn)2016條經(jīng)驗(yàn) 獲得超9個(gè)贊
你可以試試這個(gè)
WebElement temp = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//select[@class='form-control input-sm']")));
Select findValue= new Select(temp);
findValue.selectByValue("PARENT-CHILD");
添加回答
舉報(bào)