2016-11-16 101 views
0

我有使用Python 3.5硒問題,之後安裝所有的Windows更新,我所有的硒腳本壞了,我收到每一次同樣的錯誤:CLOSED - Python的硒找不到元素

Traceback (most recent call last): File "C:/Users/Carlo/Desktop/CEx/src/IE.py", line 12, in a=driver.find_element_by_xpath("//*[@id='un']") File "C:\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 293, in find_element_by_xpath return self.find_element(by=By.XPATH, value=xpath) File "C:\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 752, in find_element 'value': value})['value'] File "C:\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute self.error_handler.check_response(response) File "C:\Python35-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchWindowException: Message: Unable to find element on closed window

但我真的不明白爲什麼因爲IE的窗口是開放的!

這是我的代碼(簡單只是爲了檢查我爲什麼不能讓工作更):

import time from 
selenium import webdriver 

driver = webdriver.Ie() 
driver.get('http://gala.test-platform.celtrino.com/Login.aspx') 
time.sleep(10) 
driver.find_element_by_xpath(".//*[@id='un']") 

的代碼失敗在最後一行每次和我是雙firepath檢查和XPath是正確,所以我不明白爲什麼它不起作用。

+0

'.//*[@ ID = ')聯合國'] 「'做它確切'XPath'您使用或有一個錯字在'id'?顯然,這是'」 UN「'而不是' 「)un」' – Andersson

+0

當我在這裏寫下抱歉的時候,我剛剛說錯了:SI只是糾正了它 –

+0

我想,這不是關於你的代碼,而是關於soft。你使用最新的'IE webdriver-server'版本嗎? – Andersson

回答

0

我知道,IE瀏覽器在xpath上存在問題。它不直接支持xpath。它需要第三方工具來做到這一點。所以,我建議你嘗試使用cssSelector或其他選項。因爲元素有一個ID,所以你可以使用它。這更好。

driver.find_element_by_id("un"); 
+0

嗨,我剛剛解決了這個問題,不是關於XPath,現在命令正常工作,問題出現在IE配置中:所有區域的Internet選項 - >安全 - >「啓用保護模式」應該被選中或全部未選中(我解決了所有未選中狀態) –