簡體   English   中英

無法在下拉菜單中選擇(單擊)選項

[英]Unable to select (click) option in dropdown

我有一種情況,在單擊按鈕獲取報告之前,我必須從下拉列表(復雜對象)中選擇2個值。 我可以在第一個下拉列表(復雜)中選擇一個值,但是沒有問題,但是當我嘗試在第二個下拉列表(對象)中選擇一個選項時,它只是不選擇該選項,而是繼續單擊該按鈕。 這是腳本單擊按鈕之前情況的屏幕截圖。 如您所見,它已經為第一個下拉菜單選擇了正確的選項,看起來它為第二個下拉菜單找到了正確的選項,但是沒有單擊它:

在此處輸入圖片說明

這是我用來選擇並單擊第一個和第二個下拉菜單的代碼。 第一個下拉列表是前三行。 然后,我插入一個等待,以等待“加載”彈出式菜單無法使用。 然后,第二個下拉菜單中的另外三行與第一行幾乎相同,另一行等待單擊按鈕。

driver.findElement(By.id("dropdown1")).click();
new Select(driver.findElement(By.id("dropdown1"))).selectByVisibleText("31H-135");
driver.findElement(By.cssSelector("option[value=\"1466\"]")).click(); //there are a lot of options here and the one I need is 1466
try {
    Thread.sleep(3000);                 //3000 milliseconds is three second wait for loading popup.
} catch(InterruptedException ex) {
    Thread.currentThread().interrupt();
}
driver.findElement(By.id("Dropdown2")).click();
new Select(driver.findElement(By.id("Dropdown2"))).selectByVisibleText("31H-135-01");
driver.findElement(By.xpath("/html/body/div/form/div[3]/span/div/table/tbody/tr[1]/td/div/div/table/tbody/tr/td[1]/table/tbody/tr/td[5]/div/select/option[2]")).click();
try {
    Thread.sleep(3000);                 //3000 milliseconds is three second wait for loading popup.
} catch(InterruptedException ex) {
    Thread.currentThread().interrupt();
}

driver.findElement(By.id("ReportViewer1_ctl04_ctl00")).click();   //view report button  

這是第一個和第二個下拉菜單的一些代碼:

第一個下拉列表:

<select id="Dropdown1" style="font-family: Verdana; font-size: 8pt; width: 127px;" onchange="javascript:setTimeout('__doPostBack(\'ReportViewer1$ctl04$ctl03$ddValue\',\'\')', 0)" name="ReportViewer1$ctl04$ctl03$ddValue">
<option value="1">02C-377</option>
<option value="2">02C-378</option>
<option value="3">02G-375</option>
<option value="4">02G-376</option>
<option value="5">03G-100</option>
<option value="6">03G-101</option>
<option value="7">03G-102</option>
<option value="8">03G-103</option>
<option value="9">03G-104</option>

等等

第二個下拉列表(值基於第一個下拉列表):

<select id="Dropdown2" style="font-family:Verdana;font-size:8pt;" name="ReportViewer1$ctl04$ctl05$ddValue">
<option value="0" selected="selected"><Select a Value></option>
<option value="1">31H-135-01</option>
</select>

嘗試按值選擇或使用絕對xpath標識元素。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM