您好,我正在尝试登录公司网站,然后在该网站上自动化我的工作流程。到目前为止,我使用 pythons selenuium 创建的脚本将登录,但之后它无法找到我想要单击的元素。注意我在 jupyter notebook 上这样做
这是我用来自动化工作流程的 selenium/python 代码
from selenium import webdriver
from selenium.webdriver.common.by import By
# Create an instance of the web driver
driver = webdriver.Chrome() # Change to the appropriate web driver (e.g., Firefox(),
Safari(), etc.)
# Open a webpage
driver.get('https://3gissvrdev.xxxxxxxxx.com/3GISWebJS/')
# Find an element and click it
user_name = driver.find_element("id", "usernameField")
user_name.send_keys("CarpenCD")
pw=driver.find_element(By.ID, "passwordField")
pw.send_keys("xxxxxxx")
SigninButton=driver.find_element(By.XPATH,"//*[@id=\"signinButton\"]")
SigninButton.click()
#use this section of code to give time for web page to load after logging on
in1=input('are you ready to move on')
if in1 == 'y':
Querry=driver.find_element(By.XPATH,"//*[@id=\"d481e7896cf443e3aae933d31fc5a1d4\"]/paper-button/span")
Querry.click()
# Close the browser
#driver.quit()
然后我复制上图中突出显示的代码的 xpath,并将该路径放入上面第一个示例中代码的查询变量的 selenium/python 脚本中。
NoSuchWindowException Traceback (most recent call last)
<ipython-input-2-a0b3b1283d5d> in <module>
23 in1=input('are you ready to move on')
24 if in1 == 'y':
---> 25 Querry=driver.find_element(By.XPATH,"//*
[@id=\"d481e7896cf443e3aae933d31fc5a1d4\"]/paper-button/span")
26 Querry.click()
27
~\AppData\Roaming\Python\Python39\site-packages\selenium\webdriver\remote\webdriver.py
in find_element(self, by, value)
829 value = f'[name="{value}"]'
830
--> 831 return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})
["value"]
832
833 def find_elements(self, by=By.ID, value: Optional[str] = None) ->
List[WebElement]:
~\AppData\Roaming\Python\Python39\site-packages\selenium\webdriver\remote\webdriver.py
in execute(self, driver_command, params)
438 response = self.command_executor.execute(driver_command, params)
439 if response:
--> 440 self.error_handler.check_response(response)
441 response["value"] = self._unwrap_value(response.get("value", None))
442 return response
~\AppData\Roaming\Python\Python39\site-
packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response)
243 alert_text = value["alert"].get("text")
244 raise exception_class(message, screen, stacktrace, alert_text) #
type: ignore[call-arg] # mypy is not smart enough here
--> 245 raise exception_class(message, screen, stacktrace)
NoSuchWindowException: Message: no such window: target window already closed
from unknown error: web view not found
(Session info: chrome=113.0.5672.127)
Stacktrace:
Backtrace:
GetHandleVerifier [0x00BA8893+48451]
(No symbol) [0x00B3B8A1]
(No symbol) [0x00A45058]
(No symbol) [0x00A2D073]
(No symbol) [0x00A8DEBB]
(No symbol) [0x00A9BFD3]
(No symbol) [0x00A8A0B6]
(No symbol) [0x00A67E08]
(No symbol) [0x00A68F2D]
GetHandleVerifier [0x00E08E3A+2540266]
GetHandleVerifier [0x00E48959+2801161]
GetHandleVerifier [0x00E4295C+2776588]
GetHandleVerifier [0x00C32280+612144]
(No symbol) [0x00B44F6C]
(No symbol) [0x00B411D8]
(No symbol) [0x00B412BB]
(No symbol) [0x00B34857]
BaseThreadInitThunk [0x76717D59+25]
RtlInitializeExceptionChain [0x77DBB74B+107]
RtlClearBits [0x77DBB6CF+191]