小编Win*_*e-c的帖子

Python-Selenium:Chrome 无头设置不适用于“WebDriverWait”

以下代码可以在真正的浏览器中通过,但在无头 Chrome 中则不行。

 while True:
    try:
        #Explicitly wait
        print("Try4")
        WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "00BC0000008hfCI_listSelect")))
        print("Try5")
        ##Locate the select box
        s = driver.find_element_by_id("00BC0000008hfCI_listSelect")
        ##Unassigned queue
        Select(s).select_by_value("00BC0000008hqG8")
        time.sleep(1)
    except TimeoutException :
        print("Wrong!")
        break
Run Code Online (Sandbox Code Playgroud)

结果将是:

Try4
Wrong!
Run Code Online (Sandbox Code Playgroud)

看来无头镀铬找不到该元素。它与 Chrome 浏览器配合良好。我的 Selenium 版本是 3.14.0。

HTML 将类似于:

<div class="topNav primaryPalette" id="00BC0000008hfCI_topNav"><div class="controls"><img src="/img/s.gif" alt="Case" class="pageTitleIcon" title="Case">
<select class="title" id="00BC0000008hfCI_listSelect" name="fcf" onchange="ListViewport.instances['00BC0000008hfCI'].showFeedOrListView(this.options[this.selectedIndex].value)" title="View:"><option value="00BC0000009AFei">All Open Casa Cases</option>
    <option value="00B800000063tb2">All Open Cases</option>
    <option value="00B1A000009ZCok">Channel Upgrade Cases CCLTD</option>
    <option value="00B1A000009VKSg">Channel Upgrade Queue</option>
    <option value="00BC00000099n8S">China team's cases</option>
    <option value="00BC00000097nXg">Delete Queue</option>
    <option …
Run Code Online (Sandbox Code Playgroud)

python selenium xpath webdriver css-selectors

6
推荐指数
1
解决办法
2752
查看次数

标签 统计

css-selectors ×1

python ×1

selenium ×1

webdriver ×1

xpath ×1