0
任何人都可以幫助我解決查詢問題在Selenium Java中選擇多下拉列表
有2個下拉列表。一個下拉菜單包含所有「國家」,第二個下拉菜單包含所有「國家」。您必須從「國家/地區」Dropdow中獲取所有值。選擇國家爲「美國」,並且必須對國家(「美國」)的所有「狀態」(在第二下拉列表中)進行計數,檢索和驗證。我寫的代碼,但不能完成
public class test {
static{
System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe");
System.setProperty("webdriver.gecko.driver", "./drivers/geckodriver.exe");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver= new FirefoxDriver();
driver.manage().window().maximize();
int count=0, total=0;
driver.get("file:///C:/Users/usetr/Desktop/Country.html");
WebElement alllistBox = driver.findElement(By.id("Country"));
Select slt = new Select(alllistBox);
//Select Country India
slt.selectByVisibleText("India");
//Printing All country in dropdown and thier counts
List<WebElement> alloptions = slt.getOptions();
for (WebElement option : alloptions) {
System.out.println(option.getText());
count++;
}
System.out.println("Number of country present " + count);
類似於您選擇印度的方式,請在首次下降選擇印度。然後從第二個下拉開始計數,就像您在代碼中的第一個下拉列表所做的那樣... –
什麼是您的確切手動步驟?在你提到的有關'計數','檢索','驗證所有'狀態''的描述中,是的,我們可以'計數'和'檢索',但覈實所有的「狀態」是什麼?謝謝 – DebanjanB