標籤:位置 相同 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