wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("LOGON_selectedUser")));
WebElement mySelectElement = driver.findElement(By.id("LOGON_selectedUser"));
mySelectElement.click();
Select dropdown= new Select(driver.findElement(By.id("LOGON_selectedUser")));
dropdown.selectByVisibleText("HOTLINE-FAMILY SAFETY - Acting Supervisor");
下面是我得到的錯誤:
無法找到帶有文本的選項:HOTLINE-FAMILY SAFETY - 我試過的代理主管。價值位沒有運氣。:(
但是,我可以使用陳述句 mySelectElement.click(); 選擇下拉串列。但是當我嘗試選擇下拉選單時,我一直無法找到該元素。請幫忙。
這是DOM:
在此處輸入圖片說明
uj5u.com熱心網友回復:
該網頁是使用 Angular 構建的。請盡量誘導Explicit waits用Select class。
Select dropdown = new Select(wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//select[@name='selectedUser' and @id='LOGON_selectedUser' and @onchange]"))));
dropdown.selectByIndex(1);
或者如果這不起作用,下面應該作業
((JavascriptExecutor) driver).executeScript("return document.getElementById('LOGON_selectedUser').selectedIndex = '" index "';)
whereindex 是一個變數,嘗試傳遞索引號,如 1,2,3 等等......
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/321855.html
標籤:硒网络驱动程序
