セレンを使用して動的ドロップダウンからオプションを選択するには?

user2377826:

私は私の旅作りのフィールドからで都市を選択するドロップダウン値をクリックしようとしていますhttp://www.makemytrip.com/をしかし、古い要素参照の例外を取得。Idsは、ページの読み込みに変更してきています。コードの下にしようとしました:

driver.findElement(By.xpath(".//*[@id='hp-widget__sfrom']")).clear();
driver.findElement(By.xpath(".//*[@id='ui-id-1']"));
driver.findElement(By.xpath(".//*[@id='hp-widget__sfrom']")).click();
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeSelected(driver.findElement(By.xpath(".//*[@class='ui-menu-item'][2]"))));
DebanjanB:

ドロップダウン値などをクリックしてムンバイは、次のソリューションを使用することができます。

  • コードブロック:

    driver.get("https://www.makemytrip.com/")
    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='input_fromto checkSpecialCharacters ui-autocomplete-input' and @id='hp-widget__sfrom']"))).click();
    List<WebElement> myList = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//li[@class='ui-menu-item'][starts-with(@id,'ui-id-')]//span[@class='autoCompleteItem__label']")));
    for (WebElement element:myList)
        if(element.getText().contains("Mumbai"));
            element.click();
    
  • ブラウザスナップショット:

from_mumbai

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=221455&siteId=1