javascript - 无法单击硒文本警报
问题描述
我正在尝试单击 selenium 中的文本警报,但是当我使用单击功能时,它无法识别该命令。
我的代码如下:
chrome.find_element_by_xpath('/html/body/form/table/tbody/tr[2]/td/div/table/tbody/tr[2]/td/table[1]/tbody/tr[14]/td[1]/input[1]').click()
sleep(3)
alert = WebDriverWait(s.chrome, 3).until(EC.alert_is_present(),"Confirma a
operação?")
alert.accept
print("alert accepted")
这是我试图点击的页面元素:
input type="SUBMIT" name="BTN_ENTER" value="Confirmar" class="Button" gxevent="EENTER." onclick="if( confirm( 'Confirma a operação?')) {GX_setgridevent( 45, 12);GX_setevent('EENTER.');} else return false;" gxctx="_" onfocus="gxonfocus2(this, 59,'',45)" gxoldvalue="Confirmar"
我看到在我配置它之后,它有一个名为的选项,one click
但我不知道我必须设置什么值才能识别元素。
解决方案
当您检查alert_is_present()
内部处理的内部实现时,switch_to.alert
我们可以处理警报
chrome.find_element_by_xpath("//input[@name='BTN_ENTER']").click()
WebDriverWait(chrome, 3).until(EC.alert_is_present(),'Confirma a operação?').accept()
print("alert accepted")
更新
根据UnexpectedAlertPresentException
您可以按如下方式处理
chrome_options = Options()
chrome_options.set_capability('unhandledPromptBehavior', 'accept')
driver = webdriver.Chrome(options=chrome_options)
推荐阅读
- signalr - SignalR Core 集线器与 SignalR .NET 客户端通信?
- javascript - 如何防止用户在电子邮件输入字段中添加空格?
- android - 错误:无法解决:com.android.support:appcompat-v7:23.0.2
- android - 使用 RxJava 执行单元测试时获取 NullPointerException
- proxysql - ProxySQL 设置主机组问题
- apache-flink - Flink fs s3 shaded hadoop:使用 StreamingFileSink 到 S3 时出现 KerberosAuthException
- hive - 在作业执行期间启动的映射器
- php - Laravel curl 请求导致“403 Forbidden”响应
- if-statement - 基于另一个工作表中的复选框的 Googlesheets 条件格式
- android - 如何让 WifiManger 在 API 29 Android 中工作