消息:陈旧元素引用:元素未附加到页面文档 [英] Message: stale element reference: element is not attached to the page document

本文介绍了消息:陈旧元素引用:元素未附加到页面文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使我们几乎每天都要完成的任务自动化.我读到Python与硒结合将是完成此任务的理想选择.欢迎任何建议:)

Im trying to automate a task we do almost daily. I read that python in combination with selenium would be perfect to approach this task. Any advice is welcome :)

请参阅下面的代码.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

usernameStr = 'USERNAME'
passwordStr = 'PASSWORD'

browser = webdriver.Chrome()
browser.get('https://www.partner.co.il/he-il/login/login/?TYPE=100663297&REALMOID=06-f94d9340-8677-4c32-9f36-efd036fe99f0&GUID=&SMAUTHREASON=0&METHOD=GET&SMAGENTNAME=vmwebcms9&TARGET=-SM-HTTPS%3a%2f%2fwww%2epartner%2eco%2eil%2fcopa%2fpages%2fprotected%2fprotectedredirect%2easpx%3foriginal%3dhttps%3a%2f%2fwww%2epartner%2eco%2eil%2faccount_actions')

# fill in username 

username = browser.find_element_by_xpath('//*[@id="USER"]')
username.send_keys(usernameStr)

# fil the password

password = browser.find_element_by_xpath('//*[@id="PASSWORD"]')
password.click()
password.send_keys(passwordStr)


# press the login button

signInButton = browser.find_element_by_id('LoginBtn')
signInButton.click()

# go to the abroad page

browser.get(('https://biz.partner.co.il/he-il/biz/international/going-abroad'))

但是它返回了

=========== RESTART: C:\Program Files (x86)\Python36-32\login2.py ===========
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python36-32\login2.py", line 22, in <module>
    password.send_keys(passwordStr)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 479, in send_keys
    'value': keys_to_typing(value)})
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 628, in _execute
    return self._parent.execute(command, params)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 237, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
  (Session info: chrome=66.0.3359.139)
  (Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 10.0.14393 x86_64)

推荐答案

切换到FireFox driviver解决了使用我在此处发布的相同代码的问题

Switching to FireFox driviver solved the issue for using the same code I have posted here

这篇关于消息:陈旧元素引用:元素未附加到页面文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆