python+selenium常見問題解決方式

來源:互聯網
上載者:User

標籤:google   根據   error:   ons   技術分享   back   mos   ips   mes   

1、啟動不了瀏覽器,報錯如下:

============================= ERRORS =============================
Traceback (most recent call last):
File "D:\python_files\eclipse_wrokstation\WinshareWebAotuTest\TestCase\testBookComments.py", line 16, in setUp
self.driver = webdriver.Chrome()
File "D:\Program Files\Python\Python3\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 75, in __init__
desired_capabilities=desired_capabilities)
File "D:\Program Files\Python\Python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 154, in __init__
self.start_session(desired_capabilities, browser_profile)
File "D:\Program Files\Python\Python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "D:\Program Files\Python\Python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "D:\Program Files\Python\Python3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: unrecognized Blink revision: a10b9cedb40738cb152f8148ddab4891df876959
(Driver info: chromedriver=2.10.267521,platform=Windows NT 6.3 x86_64)

解決方式:

webdriver初始化的時候,指定一下瀏覽器的所在路徑

在聲明webdriver的時候加一句,再運行就可以了:

path = "C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"

self.driver = webdriver.Chrome(executable_path=path)

2、根據定位找不到元素:

(1)可能情況一:因為當前瀏覽器的視窗切換了(新跳轉了視窗)。

解決方案:在定位之前,先切換一下視窗

handles = driver.window_handles # 所有視窗
print ‘*‘*20,handles
for handle in handles:
if handle!=driver.current_window_handle:
print ‘switch to ‘,handle
driver.switch_to_window(handle)
print driver.current_window_handle # 列印視窗控制代碼 --名稱
break

(2)可能情況二:因為當前定位的iframe變了。

解決方案:在定位之前,先切換一下frame

driver.switch_to_frame("rightFrame") 

 (3)可能情況三:運行太快,頁面還未完全載入。

解決方案:在定位之前,先休眠1秒(或者多秒)

time.sleep(1)

 

 

python+selenium常見問題解決方式

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.