每次我运行Python / Selenium脚本时,其行为都会有所不同

时间:2019-10-17 21:48:43

标签: python-3.x selenium

Windows 10,Selenium 3.141.59,geckodriver 64位0.26,python 3.7.1

我将序列号上载到Cisco(https://cway.cisco.com/sncheck/,该重定向到Cisco身份登录页面),以确保维护范围。我正在尝试使用python代码和selenium自动执行此任务。我让我的脚本正常工作,再次运行它并收到错误消息:

“ selenium.common.exceptions.WebDriverException:消息:TypeError:矩形未定义”错误消息。

我没有进行任何更改,并且可以再运行3或4次。然后连续多次出现“ rect is undefined”错误。我已经清除了浏览器缓存,重新启动了我的机器。 。 。什么似乎都不会影响它是否起作用,只是看起来是随机的。这是我正在运行的代码。

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.action_chains import ActionChains


driver = webdriver.Firefox(executable_path="C:\\work\\selenium\\geckodriver.exe")
#driver = webdriver.Chrome(executable_path="C:\\work\\selenium\\chromedriver.exe")
#driver = webdriver.Ie(executable_path="C:\\work\\selenium\\IEDriverServer.exe")

driver.get("http://cway.cisco.com/sncheck/") 

assert "Cisco.com" in driver.title

wait = WebDriverWait(driver,10).until(EC.url_changes("https://cway.cisco.com/sncheck/"))

elem = driver.find_element_by_name("pf.username")

actions = ActionChains(driver)
actions.move_to_element(elem).perform()

elem.clear()
elem.send_keys("myuserIDhere")
elem.send_keys(Keys.RETURN)

assert "No result Found" not in driver.page_source
wait = WebDriverWait(driver,10).until(EC.url_contains("https://identity.cisco.com/"))

elem = driver.find_element_by_name("password")
actions = ActionChains(driver)
actions.move_to_element(elem).perform()

elem.send_keys("a-real-password-here")
elem.send_keys(Keys.RETURN)

自从我开始写这篇文章以来,我已经尝试运行了5次此脚本。它前3次返回“ rect undefined”,工作一次,然后最后一次返回“ rect undefined”。我用Chrome和chrome驱动程序尝试了相同的代码,并且发生了同样的事情:5次失败4次,但错误代码不同:

(selenium.common.exceptions.JavascriptException:消息:javascript错误:无法读取未定义的属性“ left”)。

然后我尝试使用IE,它可以正常工作,包括传递“密码”,但速度非常慢,大约每6秒传递一个字符。然后,在不更改代码的情况下,它开始工作并返回以下错误代码:

(selenium.common.exceptions.NoSuchElementException:消息:无法使用CSS选择器== [name =“ password”]查找元素)。

我不在乎“修复”此代码,也许它写得不好。任何帮助将不胜感激。

史蒂夫

0 个答案:

没有答案