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)
此错误消息...
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)
...暗示在为密码字段调用send_keys()
时,元素已过时。
以下是需要处理的多个事实:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = Options()
options.add_argument("start-maximized")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\ChromeDriver\chromedriver_win32\chromedriver.exe')
driver.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')
username = driver.find_element_by_xpath("//input[@id='USER']").send_keys("Alex")
driver.find_element_by_xpath("//input[@id='PASSWORD']").click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='PASSWORD']"))).send_keys("Pruteanu")
支持Chrome v65-67
这是HTML结构如下所示 错误跟踪为:
我在我的selenium java项目中不断收到一条错误消息。
我正在尝试读取联系人页面中的数据,但遇到此异常。
我试图理解为什么在我试图显示从网站获取的项目时会出现错误。我也在使用谷歌chrome浏览器。 这是我代码的其他部分 每当我使用"chromeDriver.FindElement(By.ID(something.link.text))。单击();",它会给出一个错误。我不能显示我提取的数据。 在错误消息中,它显示“OpenQA.Selenium.StaleElementReferenceExcept
我的超文本标记语言-Page包含(除其他内容外)以下内容: 在测试页面的代码中,我将执行以下操作: 这个和 然而,这个错误似乎并不合理,因为元素仍然是活动的: 我如何解决这个问题? (环境是APL。我在这里省略了一些APL细节,因为我担心它们可能会避免从核心问题上“分散注意力”) 在发帖前的研究过程中,我看到了一个问题:元素未附加到页面文档,但似乎不适用: 如图所示,我正在执行,并在找到它后立即访
我的程序抛出一条错误消息“stale element reference:element未附加到页面文档”。当我查看前面的帖子(如Python Selenium陈旧元素修复)时,我发现我没有在调用click函数后更新url。我更新了网址。然而,它并没有解决这个问题。谁能指出我哪里出错了?下面是我的代码: