当前位置: 首页 > 面试题库 >

切换到Selenium Webdriver中的Web对话框:Python

章振
2023-03-14
问题内容

我要处理Selenium Web驱动程序(Internet Explorer)下的Web对话框。我正在使用Python

在我的应用程序中,单击“图标”时,将打开一个包含一些文本框(Webelements)的Web对话框,输入一些文本后,我需要单击“保存”按钮。问题是我不知道焦点是否切换到Web对话框。这是我的代码

driver.find_element_by_xpath("//img[contains(@src,'/images/btn_add.gif')]").click()
driver.switch_to_alert()
driver.find_element_by_name("report_cutoff_date").sendkeys("10/31/2010")

这是我得到的错误

Traceback (most recent call last):
File "C:\Users\vthaduri\workspace\LDC\test.py", line 14, in <module>
driver.find_element_by_name("report_cutoff_date").sendkeys("10/31/2010")
File "C:\Python27\lib\site-packages\selenium-2.21.2-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 282, in find_element_by_name
return self.find_element(by=By.NAME, value=name)
File "C:\Python27\lib\site-packages\selenium-2.21.2-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 651, in find_element
{'using': by, 'value': value})['value']
File "C:\Python27\lib\site-packages\selenium-2.21.2-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 153, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium-2.21.2-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 147, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: u'Unable to find element with name == report_cutoff_date'

供您参考,该网络元素的名称和截止日期相同。

有人可以帮我这个忙吗?


问题答案:

试试这个:

parent_h = browser.current_window_handle
# click on the link that opens a new window
handles = browser.window_handles # before the pop-up window closes
handles.remove(parent_h)
browser.switch_to_window(handles.pop())
# do stuff in the popup
# popup window closes
browser.switch_to_window(parent_h)
# and you're back


 类似资料:
  • 我在antoher的项目中有完全相同的代码,但它在这里继续崩溃。我有。我真的不确定问题出在哪里。我尝试过切换gradle版本,从切换到。不管怎样,一切都失败了

  • 本文向大家介绍如何切换到硒框架?,包括了如何切换到硒框架?的使用技巧和注意事项,需要的朋友参考一下 我们可以借助以下方法切换到Selenium中的帧- switchTo()defaultContent() 此方法用于在帧和父帧之间来回切换。焦点转移到主页上。 switchTo()。parentFrame() 此方法用于将控件切换到当前帧的父帧。 示例

  • 问题内容: 我正在PowerShell ISE中编写脚本,并且正在使用Invoke-Sqlcmd。执行命令后,Powershell会话将切换到sqlps会话(PS SQLSERVER:>),并且我第二次无法执行脚本。我必须退出PowerShell ISE并重新启动。 所以我的问题是:如何从sqlps切换回常规ps或如何防止Invoke-Sqlcmd切换会话。 这不起作用: 问题答案: 该模块的行为

  • 你好,有帮助的硒窗口和框架切换的家伙(或女孩),

  • 在教程的这个部分,我们将介绍对话框。 对话框窗口或者对话框是大多数现代GUI程序一个不可或缺的部分。对框框被定义为一个或更多人之间的对话。在计算机程序中,对话框就是用来与程序对话的窗口。并且反之亦然,对话框是用来输入数据,更改数据,改变应用程序的设置等。对话框是用户和计算机程序之间重要的交流途径。 Message dialogs 消息对话框是一种很便利的对话框,它为程序的用户提供各种消息。消息一般

  • 对话框的内容不是在页面最初可见,而是在用户操作时显示额外的信息。 Toasts Materialize 提供了非常简单的方法,来弹出一些信息,同时也不会让用户感到突兀。这些 Toasts 显示的位置和大小会随着你的设备的不同而改变。 在 JavaScript 中调用 Materialize.toast() 方法来使用。 // Materialize.toast(message, displayLe