invzbl3:
私は、指定した上でクリックする必要がありますli
:ドロップダウンリストを使用して要素All subject areas
の上にウェブサイト。問題は次のとおりです。指定をクリックすることはできませんli
セレンを使用して要素。
例えば、私は次のように足すだ場合:
String textInput = "Agricultural and Biological Sciences";
//...
// open the dropdown so the options are visible
driver.findElement(By.className("dropdown"));
// Get all of the options of dropdown list
WebElement ulElement = driver.findElement(By.cssSelector("ul.dropdown-options.dropdown-element"));
List<WebElement> opts = ulElement.findElements(By.xpath(".//li/a"));
そして、指定された選択しようとしているli
要素を:
// Loop through the options and select the one that matches
for (WebElement opt : opts) {
if(opt.getText().equals(textInput)){
opt.click();
//...
}
}
条件は、単にプログラムによってスキップされます。
私のようなバリアントに変更した場合:
// Loop through the options and select the one that matches
for (WebElement opt : opts) {
if(!opt.findElements(By.xpath("//*[contains(text(), '" + textInput + "')]")).isEmpty()) {
opt.click();
//...
}
}
条件は無視され、正常に渡したが、その後のプログラムは、ボタンをクリックしないと、リストが閉じられていません。
誰かがどのようにここでの問題を解決するために私をお勧めすることはできますか?
DebanjanB:
click()
テキストを持つ要素の農業と生物科学(雑多)ドロップダウンから、あなたが誘導する必要がWebDriverWaitをするためにelementToBeClickable()
、あなたは以下を使用することができます ロケータ戦略:
XPathの:
driver.navigate().to("https://www.scimagojr.com/journalrank.php?country=UA&page=1"); new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[normalize-space()='All subject areas']"))).click(); new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[normalize-space()='All subject areas']//following-sibling::ul[1]//li/a[normalize-space()='Agricultural and Biological Sciences']"))).click();
ブラウザスナップショット: