Selenium 的 Select 類中有哪些不同的方法?
Selenium 的 Select 類中可用的各種方法如下所示:
selectByVisibleText(String args)
此方法最常用於下拉列表。使用此方法,在下拉列表和多選框中選擇選項非常簡單。它以字串作為引數,不返回值。
語法:
Select s = new Select(driver.findElement(By.id("<< id exp>>"))); s.selectByVisibleText("Selenium");
selectByIndex(String args)
此方法獲取下拉列表中要選擇的選項的索引。它以 int 作為引數,不返回值。
語法:
Select s = new Select(driver.findElement(By.id("<< id exp>>"))); s.selectByIndex(1);
selectByValue(String args)
此方法獲取下拉列表中要選擇的選項的值。它以字串作為引數,不返回值。
語法:
Select s = new Select(driver.findElement(By.id("<< id exp>>"))); s.selectByValue(“Testing”);
getOptions()
此方法以 Web 元素列表的形式獲取 select 標籤下所有選項。它沒有引數。
語法:
Select s = new Select(driver.findElement(By.id("<< id exp>>"))); s.getOptions();
deSelectAll()
此方法用於多選下拉列表,並取消所有選定的選項。
語法:
Select s = new Select(driver.findElement(By.id("<< id exp >>"))); s.deSelectAll();
deselectByVisibleText(String args)
此方法用於根據與引數類似的顯示文字,取消選擇下拉列表中的所有選項。它以字串作為引數,不返回值。此方法用於多選下拉列表。
語法:
Select s = new Select(driver.findElement(By.id("<< id exp>>"))); s.deselectByVisibleText("Selenium");
deselectByIndex(String args)
此方法獲取要取消選擇下拉列表中選項的索引。它以 int 作為引數,不返回值。此方法用於多選下拉列表。
語法:
Select s = new Select(driver.findElement(By.id("<< id exp>>"))); s.deselectByIndex(1);
deselectByValue(String args)
此方法獲取要取消選擇下拉列表中選項的值。它以字串作為引數,不返回值。此方法用於多選下拉列表。
語法:
Select s = new Select(driver.findElement(By.id("<< id exp>>"))); s.deselectByValue(“Testing”);
廣告