2016-10-03 4 views
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())); 
     } 
    } 
} 
+0

私はそれを一貫して動作させることができなかったため、答えとして含めていません... 5時間のうち2回働いただけです...このコードで試してください... ChromeOptions chop =新しいChromeOptions(); chop.addArguments( "テストタイプ"); chop.addArguments( "start-maximized"); chop.addArguments( " - allow-running-insecure-content"); WebDriverドライバ=新しいChromeDriver(チョップ);また、私は最初のドロップダウンをクリックする前に5秒のThread.sleepを入れました... – Grasshopper

答えて

0

あなたが作業しているWebアプリケーションが、最初の選択ドロップダウンにonblurを使用していることを願っています。まず最初にJavaScriptをトリガするように選択するための次のドロップダウンに集中する方が良いです。 2番目の選択ドロップダウンのwebdriverwaitの上に次のコードを含めてみてください。

WebElement element = driver.findElement(By.id("_impreseiscritte_WAR_serviziportalealbo100SNAPSHOTesercizioalbo_comuniList")); 
new Actions(selenium).moveToElement(element).perform(); 
new WebDriverWait(driver,90).equals((((JavascriptExecutor) selenium).executeScript("return document.readyState").equals("complete"))); 

幸運!

関連する問題