私はドロップダウンを反復し、最初の値を選択し、次に検索をクリックし、再度2番目の値を選択して再度検索を実行します。このコードでは、1つのオプションのみを選択しようとしましたが、一つ
ベストアンサー
これは本当のHTMLタグではないので、すべてシミュレートされ、無制限に設計できます。実際のHTMLが実際に含まれるまでは、一般的なアドバイスがあります。
Step 1: Identify the link to expand the select
options
WebElement selectLink = driver.findElement(By.id(buttonId));
Step 2: Identify the individual links for each
of the options in the simulated select
List optionLinks = driver.findElements(By.cssSelector(commonOptionPath));
Step 3: Write a method to click the select link
(to “pop open” the select options)
public void clickSelectLink() {
selectLink.click();
}
Step 4a: Write a method to search through the
options list comparing text with what you want to click
public void clickOptionByName(String name) {
for (int i = 0; i < optionLinks.size(); i++) {
if (optionLinks().get(i).getText().equalsIgnoreCase(name)) {
optionLinks.get(i).click();
return;
}
}
//Error out because we could no find a match
}
Step 4b: Write a method that clicks on a
specific index in the option list
public void clickOptionByIndex(int index) {
optionLinks.get(index).click();
}
残念ながら、いくつかのショートカットが可能です。それはすべてシミュレートされているため、これを処理する組み込みのセレンメソッドはありません。唯一の可能性は、開発者がオプションごとにランダムでないIDを挿入したことですが、これは0.01%のチャンスになります。