使用JavascriptExecutor发送Keys并单击web元素(Using JavascriptExecutor to sendKeys plus click on web element)
我正在尝试在新选项卡中打开一个链接,然后在Firefox浏览器中使用Java中的selenium切换到该选项卡。 我的理解是,为了做到这一点,我需要使用发送键组合。
为了在同一个窗口中打开链接,我一直在使用这样的东西:
WebElement we = driver.findElement(By.xpath("//*[@id='btn']")); JavascriptExecutor executor = (JavascriptExecutor) driver; executor.executeScript("arguments[0].click();", we);
以上对我来说很好。
现在我也试图发送凯斯,如下所示,这是行不通的:
JavascriptExecutor executor = (JavascriptExecutor) driver; executor.executeScript("keyDown(Keys.CONTROL) .keyDown(Keys.SHIFT) .click(arguments[0]) .keyUp(Keys.CONTROL) .keyUp(Keys.SHIFT);", we);
任何建议? 我无法弄清楚sendKeys到JavascriptExecutor的正确语法。 我已经看过一些使用Actions的类似解决方案,但这对我来说也没有用。
I'm trying to open a link in a new tab, then switch to that tab, in a Firefox browser, using selenium in Java. It's my understanding that in order to do this, I need to use a send keys combination.
In order to open the link in the same window, I've been using something like this:
WebElement we = driver.findElement(By.xpath("//*[@id='btn']")); JavascriptExecutor executor = (JavascriptExecutor) driver; executor.executeScript("arguments[0].click();", we);
The above was working fine for me.
Now I'm trying to also sendKeys, as in below, which is not working:
JavascriptExecutor executor = (JavascriptExecutor) driver; executor.executeScript("keyDown(Keys.CONTROL) .keyDown(Keys.SHIFT) .click(arguments[0]) .keyUp(Keys.CONTROL) .keyUp(Keys.SHIFT);", we);
Any advice? I can't figure out the correct syntax to sendKeys to JavascriptExecutor. I've seen some similar solutions using Actions, but this hasn't worked for me either.
原文:https://stackoverflow.com/questions/31632923
最满意答案
你应该托管一个nexus存储库来保存你自己的工件,然后让maven与它交谈以下载你自己的库(就像第三方库一样)
you should host a nexus repository to hold your own artifacts, and let maven talk to it to download your own libraries (just like third party libraries)
相关问答
更多-
在SO中已经提出了类似的问题: 如何将包含文件的现有文件夹添加到SVN? 你需要: 从您要提交的存储库中checkout出(您必须知道此存储库的URI)。 将Maven项目放在刚签出的文件夹中。 add要提交的所有文件。 commit SVN。 A similar question was already asked here in SO: How to add an existing folder with files to SVN? You will need to: checkout from the ...
-
java查找哪些jar与哪些java源文件一起使用(java Finding which jars are used with which java source files)[2023-04-14]
Tattletale最终给了我第一级的依赖关系,这是我需要构建我的ivy.xml或pom.xml文件。 它偶尔会错过一两次,但其他情况下效果不错。 Tattletale ended up giving me the first level of dependencies which is what I need to build my ivy.xml or pom.xml file. It misses one or two occasionally, but otherwise it works pret ... -
我想已经提出了类似的问题,请参阅: 如何在一个命令行中下载特定的Maven工件? Maven依赖插件应该可以帮到你。 I think similar question has been already asked, see: How can I download a specific Maven artifact in one command line? Maven dependency plugin should do the job for you.
-
你应该托管一个nexus存储库来保存你自己的工件,然后让maven与它交谈以下载你自己的库(就像第三方库一样) you should host a nexus repository to hold your own artifacts, and let maven talk to it to download your own libraries (just like third party libraries)
-
有两种方法可以解决您的问题! 如果您只想将文件添加到jar中,可以使用resources标签添加它们
false lib *.jar 通过maven连接SVN(connecting SVN through maven)[2022-08-13]
SVN不适用于您的情况。 日志消息 'svn' is not recognized as an internal or external command, 表示系统上未安装SVN。 您需要先安装SVN客户端。 之后,Maven将能够查看该项目。 SVN is not working in your case. The log message 'svn' is not recognized as an internal or external command, means that SVN is not ...运行mvn dependency:analyze 。 它应该做的工作。 Run mvn dependency:analyze. It should do the work.Maven替代品插件是否满足您的需求? Is the Maven replacer plugin a solution for your need?通过右键单击其文件名来下载jar - > Save链接返回损坏的jar文件。 单击文件详细信息中的“原始”,返回正确的文件。 Downloading jar by means of right click on its file name --> Save link returns corrupted jar files. Clicking on "Raw" in the file details, return the correct file.Maven Assembly Plugin实际上忽略了addMavenDescriptor参数,并且永远不会在生成的程序集中包含Maven描述符。 这可以在源代码中看到:只有META-INF/MANIFEST.MF文件可能被添加到JAR存档中。 我找不到关于此问题的现有JIRA问题,所以我继续创建了MASSEMBLY-835来跟踪这个问题。 现在解决方法是在汇编描述符中自己添加文件:相关文章
更多- Beware the Web Fads of Yesteryear
- web storm使用和配置
- The content of element type "package" must match "...
- JAVA WEB
- 图片篇-高性能WEB开发
- Web Services 三种基本的元素介绍
- 在web应用中如何对异常进行处理
- Tomcat的部署web项目
- 从Web到移动应用的设计思维转换
- 微信Web APP应用
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)