Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 每次运行Python/Selenium脚本时,它的行为都不同_Python 3.x_Selenium - Fatal编程技术网

Python 3.x 每次运行Python/Selenium脚本时,它的行为都不同

Python 3.x 每次运行Python/Selenium脚本时,它的行为都不同,python-3.x,selenium,Python 3.x,Selenium,Windows 10、Selenium 3.141.59、geckodriver 64位0.26、python 3.7.1 我将序列号上传到Cisco(它会重定向到Cisco身份登录页面),以确保维护范围。我正在尝试使用python代码和selenium自动化此任务。我让我的脚本开始工作,第二次运行时收到一条错误消息: “selenium.common.exceptions.WebDriverException:Message:TypeError:rect未定义”错误消息 我没有做任何改变,它又

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

我将序列号上传到Cisco(它会重定向到Cisco身份登录页面),以确保维护范围。我正在尝试使用python代码和selenium自动化此任务。我让我的脚本开始工作,第二次运行时收到一条错误消息:

“selenium.common.exceptions.WebDriverException:Message:TypeError:rect未定义”错误消息

我没有做任何改变,它又运行了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次返回“未定义的矩形”,工作一次,最后一次返回“未定义的矩形”。我在Chrome和Chrome驱动程序中尝试了相同的代码,同样的情况也发生了:5次中有4次失败,但错误代码不同:

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

然后我尝试了IE,它成功了,包括传递“密码”,但速度非常慢,大约每6秒传递一个字符。然后,在代码没有任何更改的情况下,它开始关闭并返回此错误代码:

(selenium.common.exceptions.NoSuchElementException:Message:无法使用css选择器==[name=“password”]找到元素)

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


Steve

python代码中的哪些行被视为抛出异常?当我刚才转到URL时,它重定向到。硒会阻塞重定向。通常直接转到页面而不是返回重定向的页面是更可靠的方法。。。如果您不需要移动或清除操作,请将其忽略。发送键将设置焦点,所有这些。。。您当前使用的等待不是必需的。Selenium已在等待页面加载。使用webdriverwaits查找要与之交互的元素。(等待元素对于文本字段是可交互的…)使用WebDriverWait等待每个元素的元素可见性。python代码中的哪些行被视为抛出异常?当我刚才转到URL时,它重定向到。硒会阻塞重定向。通常直接转到页面而不是返回重定向的页面是更可靠的方法。。。如果您不需要移动或清除操作,请将其忽略。发送键将设置焦点,所有这些。。。您当前使用的等待不是必需的。Selenium已在等待页面加载。使用webdriverwaits查找要与之交互的元素。(等待元素可与文本字段交互…)使用WebDriverWait等待每个元素的元素可见性。