0

我是 selenium 的新手,在从下拉列表中选择一个选项时遇到问题。

HTML 代码:

<select id="fileselection" class="selectpicker show-menu-arrow" name="fileselection" onchange="function1('SELECTEDFILES', 'True')" multiple="" data-width="100%" data-style="btn-info" data-action-box="true" data-live-search="true" data-size="5" tabindex="-98">
    <option value="URL_OF_FILE_1">
       Filename_1.zip
    </option>
    <option value="URL_OF_FILE_2">
       Filename_2.zip
    </option>
</select>

URL 还包含文件名

例子:

www.yahoo.com/Filename_1.zip

www.yahoo.com/Filename_2.zip

我的代码:

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//select[@id='fileselection']//option[contains(.,'Filename_1.zip')]")))
ele = driver.find_element_by_xpath("//select[@id='fileselection']//option[contains(.,'Filename_1.zip')]")
ele.click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//select[@id='fileselection']//option[@value='URL_OF_FILE_1')]")))
ele = driver.find_element_by_xpath("//select[@id='fileselection']//option[@value='URL_OF_FILE_1')]")
ele.click()

我在最后一步(ele.click())收到错误。等待并查找元素步骤工作正常。

Element <option> could not be scrolled into view

谢谢!

4

0 回答 0