0
2つのドロップダウンリストがあります。 2番目は最初のものから選択が行われるまで空です。しかし、最初にセレンを選択してselect.selectByIndex()
またはいずれかの選択メソッドを使用すると、2番目のドロップダウンには値が設定されません。セレンがダイナミックセレクトを更新していません
public class ScraperTwo {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "/home/user/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://www.alboautotrasporto.it/web/portale-albo/imprese-iscritte");
Select firstDropDown = new Select(driver.findElement(By.id("_impreseiscritte_WAR_serviziportalealbo100SNAPSHOTesercizioalbo_provinceList")));
firstDropDown.selectByIndex(10);
(new WebDriverWait(driver, 30)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
Select innerSelect = new Select(d.findElement(By.id("_impreseiscritte_WAR_serviziportalealbo100SNAPSHOTesercizioalbo_comuniList")));
return innerSelect.getOptions().size() > 0;
}
});
WebElement secondDropDown = driver.findElement(By.id("_impreseiscritte_WAR_serviziportalealbo100SNAPSHOTesercizioalbo_comuniList"));
List<WebElement> allOptions = secondDropDown.findElements(By.tagName("option"));
for(WebElement option: allOptions) {
System.out.println(String.format("Value is %s", option.getText()));
}
}
}
私はそれを一貫して動作させることができなかったため、答えとして含めていません... 5時間のうち2回働いただけです...このコードで試してください... ChromeOptions chop =新しいChromeOptions(); chop.addArguments( "テストタイプ"); chop.addArguments( "start-maximized"); chop.addArguments( " - allow-running-insecure-content"); WebDriverドライバ=新しいChromeDriver(チョップ);また、私は最初のドロップダウンをクリックする前に5秒のThread.sleepを入れました... – Grasshopper