Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97803

Python / Selenium script behaves differently each time I run it

$
0
0

Windows 10, Selenium 3.141.59, geckodriver 64-bit 0.26, python 3.7.1

I upload serial numbers to Cisco (https://cway.cisco.com/sncheck/ which redirects to a Cisco identity log in page) to ensure maintenance coverage. I am trying to automate this task using python code and selenium. I got my script to work, ran it a second time and got an error message:

"selenium.common.exceptions.WebDriverException: Message: TypeError: rect is undefined" error message.

I made no changes, and it ran fine 3 or 4 more times. Then gave the "rect is undefined" error several times in a row. I've cleared the browser cache, restarted my machine . . .nothing seems to effect whether it works or not, just seems random. Here's the code I am running.

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)

I've tried to run this script 5 times since I began this post. It returned the "rect undefined" the first 3 times, worked once, then returned the "rect undefined" the last time. I tried the same code with Chrome and the chrome driver and the same same sort of thing happens: it fails 4 out of 5 times but with a DIFFERENT error code:

(selenium.common.exceptions.JavascriptException: Message: javascript error: Cannot read property 'left' of undefined).

I then tried IE, and it worked, including passing the "password" but it was very slow, passing one character about every 6 seconds. Then, without any change to the code, it began to work off and on returning this error code:

(selenium.common.exceptions.NoSuchElementException: Message: Unable to find element with css selector == [name="password"]).

I don't care about "fixing" this code, maybe it's just poorly written. Any help would be appreciated.

Steve


Viewing all articles
Browse latest Browse all 97803

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>