如何驗證我們是否可以在 Selenium 中靜態下拉選單中選擇多個選項?
藉助 isMultiple() 方法,我們可以驗證是否可以在 Selenium 中靜態下拉選單中選擇多個選項。它返回布林值 true 或 false。
示例
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import java.util.List; import org.openqa.selenium.support.ui.Select; public class OptionsMultiple{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://tutorialspoint.tw/tutor_connect/index.php"; Select s = new Select(driver.findElement(By.xpath("//select[@name=’selType’]"))); // isMultiple() returns a boolean value boolean result = s.isMultiple(); System.out.println(result); driver.close(); } }
廣告