ここに初めて。あなたが助けてくれるかもしれない問題があります。クロムウェブドライバの自動化では、クリックして切り替えるドロップダウンメニューがあります。私はリストアイテムを選択できる必要があります。ここにメニューのコードがあります。
<button type="button" class="multiselect dropdown-toggle btn btn-default" data-toggle="dropdown" title="None selected" aria-expanded="true">None selected </button>
class="multiselect-container dropdown-menu"
次のことを通してそれとやりとりしようとする私の試みは失敗しました。
new Select(driver.findElementByXPath("//button[@type='button']")).selectByVisibleText("TEST");
それ以上の情報が必要な場合は、何が必要かを熟知していないか尋ねてください。 どうもありがとう
更新; 返信をありがとう。
“オプション名で選択”が機能していないようです。私のxpathでそのコードを使うと、次のようになる
org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "button"
“オプション値で選択”は同じエラーを返します。
私はchrome selenium
IDEを使ってxpathとclassをcssで見つけましたが、以下のようにDropboxを切り替えることができず、次のエラーが出るので間違いかもしれません。また、私は別の要素と対話することができるように正しいiframeにあります。
driver.findElementByXPath("//button[@type='button']").click();
driver.findElementByCssSelector(".multiselect.dropdown-toggle.btn.btn-default").click();
org.openqa.selenium.ElementNotVisibleException: element not visible
私は間違った方法で要素を参照することがありますか? どうもありがとう
update2:近づいているような気がします。
driver.findElementById("ptp_sl").click();
unknown error: Element is not clickable at point
ベストアンサー
以下のコードは、ドロップダウンの位置を特定し、ドロップダウンに存在するオプションのリストを表示します。以下の最初の2行のコードがドロップダウンを見つけるかどうかを確認します。
WebElement we = driver.findElement(By.xpath("//select[@class='userdropdown']"));
Select dropdown = new Select(we);
List alloptions = dropdown.getOptions();
for(WebElement option:alloptions)
{
dropdown.selectByVisibleText(option.getText());
System.out.println(option.getText());
}