下面列出了Selenium中Select类下可用的各种方法-
selectByVisibleText(字符串参数)
此方法是下拉菜单中最常用的方法。使用此方法在下拉菜单和多重选择框中选择一个选项非常简单。它使用String参数作为参数,并且不返回任何值。
语法-
Select s = new Select(driver.findElement(By.id("<< id exp>>")));
s.selectByVisibleText("Selenium");selectByIndex(字符串参数)
此方法在下拉列表中选择选项的索引。它以int参数作为参数,不返回任何值。
语法-
Select s = new Select(driver.findElement(By.id("<< id exp>>")));
s.selectByIndex(1);selectByValue(字符串参数)
此方法采用下拉菜单中要选择的选项的值。它使用String参数作为参数,并且不返回任何值。
语法-
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)
此方法用于根据显示的与参数相似的文本从下拉列表中取消选择所有选项。它使用String参数作为参数,并且不返回任何值。此方法用于多选下拉菜单。
语法-
Select s = new Select(driver.findElement(By.id("<< id exp>>")));
s.deselectByVisibleText("Selenium");deselectByIndex(字符串参数)
此方法在下拉列表中使用索引取消选择选项。它以int参数作为参数,不返回任何值。此方法用于多选下拉菜单。
语法-
Select s = new Select(driver.findElement(By.id("<< id exp>>")));
s.deselectByIndex(1);deselectByValue(字符串参数)
此方法采用该值来选择下拉菜单中的选项。它使用String参数作为参数,并且不返回任何值。此方法用于多选下拉菜单。
语法-
Select s = new Select(driver.findElement(By.id("<< id exp>>")));
s.deselectByValue(“Testing”);