- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
为了自动化我的测试应用程序,我需要在新窗口而不是选项卡中打开一些链接。请记住,我没有明确在新选项卡中打开链接,而是我的网络应用程序在单击链接后自动将用户引导到新选项卡中。
我为什么要这样做?
因为在 Chrome 浏览器上运行测试会关闭主选项卡并保持打开新打开的选项卡。最终测试失败。因此最终目的是打开新窗口而不是选项卡并使用 driver.getWindowHandles()
正确处理它。
到目前为止我做了什么?
我试图在 Chrome 中找到某种功能设置或配置文件,它会自动在新窗口中打开本应在选项卡中打开的链接。但没有找到任何令人信服的解决方案,大多数建议是 CTRL+CLICK在链接上。
最佳答案
我不是网页设计大师,但我可以建议以下场景:
// Get required page
// Excecute below JavaScript with JavaScriptExecutor
var reference = document.querySelector('a#someID').getAttribute('href'); // You can use your specific CSS Selector instead of "a#someID"
document.querySelector('a#someID').setAttribute("onclick", "window.open('" + reference + "', '', 'width=800,height=600')")
document.querySelector('a#someID').removeAttribute('href')
// Find target link
// Click on it
此代码应允许您对目标 Web 元素的 HTML
源代码进行更改,以强制其在新浏览器窗口中打开。
注意,使用此代码元素在页面上的外观将发生变化,直到页面刷新
附注您没有提到您的编程语言,因此没有完整的实现...但是,这是 Python
实现示例:
from selenium import webdriver as web
dr = web.Chrome()
dr.get('https://login.live.com/login.srf?&wreply=https%3a%2f%2foutlook.live.com%2fowa%2f%3fnlp%3d1%26realm%3dlogin.live.com')
dr.execute_script("""
var reference = document.querySelector('a#ftrTerms').getAttribute('href');
document.querySelector('a#ftrTerms').setAttribute("onclick", "window.open('" + reference + "', '', 'width=800,height=600')")
document.querySelector('a#ftrTerms').removeAttribute('href')
""")
link = dr.find_element_by_id('ftrTerms')
link.click()
关于google-chrome - 如何使用 webdriver 在 chrome 中打开新窗口而不是新选项卡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41480851/
我正在尝试使用特定路线打开一个新窗口,但似乎路线页面未正确加载。将从FrmApprovalMain.js打开新的 Electron 窗口,并应使用FrmPOdet.js打开新窗口。但是,当它打开时,会
我对 Tkinter 比较陌生,我需要帮助。 当从父窗口单击按钮时,我创建了一个新窗口。新窗口是 def new_Window。但我似乎无法获取窗口中的信息,如下编码: from tkinter im
我正在尝试使用 Javascript 从空白 iframe 中创建一个重定向,该 iframe 将定向到新窗口或选项卡中的 URL。 更具体地说,我试图让一个 Facebook 标签指向我公司的网页,
在问这个问题之前,我确实搜索了很多。抱歉,如果这是一个简单的问题。 在我的 wxWidgets 应用程序中,我想从菜单选项中新建一个 wxHtmlWindow。 (我已经正确显示了我的主应用程序窗口)
我认为我不是很了解这个,因为我对 jquery 还很陌生。我有一个隐藏了 3 个食谱的页面。单击食谱 A 的链接时,它会以模式打开。我希望能够只打印食谱的内容。所以我打开一个新窗口(非模态)并尝试将食
我想在带有可滚动文本框的现有主 Windwoe 旁边创建一个新窗口。 我在主窗口中按下“打开新窗口”按钮,然后它应该会打开一个带有可滚动文本框的新窗口。 在 form2 中 在 WPF 中,您可以在主
我正在使用 Simple Icons 制作自定义 Pinterest Pin It 按钮,我正在使用 Pinterest Widget Builder 给我的链接。在默认的 Pin It 按钮上,它会
我的表单上出现一个确认对话框,单击“确定”后会将用户重定向到另一个页面。 但是,是否可以在新窗口中打开该页面(例如 target="_blank") 我正在使用的代码是: var answer=con
相关但处于休眠状态:Javascript to open URL within a new Tab和其他一些...... 我有一个客户坚持认为特定链接需要在新选项卡中打开,而不是在窗口中打开。它由表单
我遇到了 Android 问题 WebView , 我想用 target='_blank' 打开一个 URL在同一WebView ,就像所有其他的一样URLs正在开放。 另请注意,我重写了 WebVi
可以从 Controller 重定向到某个 url 并同时在新窗口中打开该 url 吗? 最佳答案 不是真的来自 Controller Action 。 重定向是带有 301/302 状态代码和 Ra
在 Electron vue 中,我想为每个新窗口创建新的 vue 实例。这工作正常,直到我想将路由器子组件加载到新窗口。例如我有条目 add: path.join(__dirname, '../sr
案例1: var printWindow = window.open("", "print_window"); if(printWindow) { printWindow.addEventLi
我需要使用 Javascript Window.Open 函数打开一个新的 (_blank) 窗口。 URL 编码的回车符/换行符 (%0A) 似乎不起作用。有谁知道解决这个问题?例如,我有以下 UR
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 1年前关闭。 Imp
当 flash 有键盘焦点时,CTRL+T(新标签)和 CTRL+N(新标签)窗口)被闪光拦截。 有没有办法将这些事件传递给浏览器以便它们工作(打开新选项卡,打开新浏览器)或者是否有用于这些操作的 j
我有一个 ASP.Net MVC 页面,上面有一个非常简单的表单:一个文本框和一个提交按钮。该表单使用标准的 mvc BeginForm() 语法: 当直接打开页面时,一切正常。 但是,我们有另一个
如果您对此问题感兴趣,请阅读下面的更新 #2 ;) 假设我将此代码放入我的扩展程序的 JS 中。 var reader = { onInputStreamReady : function(in
我是一名优秀的程序员,十分优秀!