【selenium+python】關於使用selenium時的幾個問題1

來源:互聯網
上載者:User

標籤:位置   相同   except   typeerror   方法   lin   城市   erro   mon   

問題:selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

原因:提示時沒有添加到PATH環境變數,找不到webdriver

解決:win10下曾經把chromedriver所在目錄添加到PATH環境變數,但是仍然報相同錯誤,經搜尋,發現把chromedriver.exe放到和python指令碼相同的目錄下即可運行成功!

問題:TypeError: ‘WebElement‘ object is not iterable

原因:選擇多個HTML頁面元素的時候應該用方法的複數

解決:改用find_elements_by_tag_name,這裡element有s

問題:AttributeError: ‘WebElement‘ object has no attribute ‘sendkeys‘

原因:代碼裡寫了sendkeys,但是沒有這個方法(實際是send_keys)

解決:把sendkeys改為send_keys(這個問題純屬粗心= =)

背景:在使用selenium進行爬蟲的時候,需要輸入關鍵字搜尋,但是就出現了開啟網頁,輸入關鍵字後拋出異常的情況。

問題:開啟了網頁後,拋異常,然後瀏覽器自動關閉

原因:經調試發現拋異常的位置在:

WebDriverWait(driver,15).until(

                    EC.title_contains(unicode(to_city))

                )

這裡的意思是等待搜尋結果頁載入出包含關鍵字的網頁才繼續下一步,但是由於上一步輸入to_city值的時候意外點到其他城市名,導致這一步拋出異常無法繼續

 

【selenium+python】關於使用selenium時的幾個問題1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.