我正在为我的公司实现IdentiGO应用程序的自动化,但出现以下错误:
Internal Server Error: /identigo
Traceback (most recent call last):
File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/django/views/generic/base.py", line 97, in dispatch
return handler(request, *args, **kwargs)
File "/Users/jane/Code/maynard_env/maynard/employee/views.py", line 63, in post
driver.main(employee)
File "/Users/jane/Code/maynard_env/maynard/employee/driver.py", line 31, in main
WebDriverWait(driver, 1000000).until(EC.presence_of_element_located((By.XPATH, '/html/body/div[5]/div[3]/div/button/span'))).click()
File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: Element <span class="ui-button-text"> could not be scrolled into view
这是我的代码,由于与我的问题无关,所以省略了指向此页的脚本。在
^{pr2}$On the page prior to this code, where the user selects an appointment date and time; I want the script to wait for the "Go" button to be pushed, then click on "Continue" in the following screenshot:
如果您想查看确切的页面,请转到thisurl,然后您必须使用以下信息发出一系列POST请求:
任何建议都将不胜感激!在
下面是一个JS摆弄页面的html:
https://jsfiddle.net/khf4tym3/
当我点击“查看页面源代码”时,弹出的html不会显示在源代码中,所以我假设它是用JS生成的。在
<div class="ui-dialog-buttonset">
<button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false">
<span class="ui-button-text">Continue</span>
</button>
</div>
如果我将WebDriverWait(driver, 1000000)
更改为WebDriverWait(driver, 30)
,则会得到以下错误:
Internal Server Error: /identigo
Traceback (most recent call last):
File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/django/views/generic/base.py", line 97, in dispatch
return handler(request, *args, **kwargs)
File "/Users/jane/Code/maynard_env/maynard/employee/views.py", line 63, in post
driver.main(employee)
File "/Users/jane/Code/maynard_env/maynard/employee/driver.py", line 34, in main
element=WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.XPATH,"//div[@class='ui-dialog-buttonset']/button[@class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only']/span[contains(.,'Continue')]")))
File "/Users/jane/Code/maynard_env/env/lib/python3.7/site-packages/selenium/webdriver/support/wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
到目前为止项目的代码,所以你可以跳过论坛条目。在
https://jsfiddle.net/93k5s2xg/1/
工作方案:
WebDriverWait(driver, 20).until(expected_conditions.element_to_be_clickable((By.XPATH, "//div[starts-with(@aria-describedby, 'ui-id-')]//span[@class='ui-button-text' and text()='Continue']"))).click()
使用下面的xpath并单击它。在
如果以上点击不工作,然后尝试下面一个。在
^{pr2}$或者可以使用javascripts executor单击。在
EDITED
尝试下面的代码,它是点击继续按钮,其中继续和取消按钮有一次单击“继续”,您将看到另一个“继续”按钮点击。这个我已经从计划应用程序更新了代码。在
编辑了其余代码。
这段代码在chrome浏览器和Windows10操作系统上运行良好,我已经测试过几次了。在
此错误消息。。。在
…意味着WebDriver实例,即驱动程序无法滚动Viewport中的元素来调用
click()
。在首先,由于您的用例是在元素上调用
^{pr2}$click()
,理想情况下不是使用presence_of_element_located()
,您需要使用ExpectedConditions作为element_to_be_clickable()
:您可以在以下位置找到一些详细讨论:
另一种方法是,根据错误消息,在调用^{之前,在视口中滚动一个元素,还可以使用Element.scrollIntoView()方法。在
详细讨论请参见: -What is the difference between the different scroll options?
在这一点上值得一提的是,以下方法:
将自动滚动视口中的元素。在
详细讨论请参见: -How to scroll a webpage using selenium webdriver in Python without using javascript method execute_script()
本用例
文本为继续的按钮位于顶层内容中,但在模式对话框中呈现。在
开发工具快照:
由于所需元素位于模式对话框中,因此要定位并调用元素上的
click()
,您必须为element_to_be_clickable()
归纳WebDriverWait,并且可以使用以下Locator Strategy:使用
^{3美元XPATH
:注意:您必须添加以下导入:
开发工具快照:
相关问题 更多 >
编程相关推荐