如何从Selenium中调用JavaScript函数? [英] How to call a JavaScript function from within Selenium?

查看:56
本文介绍了如何从Selenium中调用JavaScript函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从Firefox中的Selenium WebDriver调用JavaScript函数.登录网站后,我在Firebug的命令编辑器中使用以下命令来调用文件上传应用程序:

I need to call a JavaScript function from Selenium WebDriver in Firefox. I use this command in Firebug's Command Editor to invoke a file upload application after logged into my website:

infoPanel.applicationManager.changeApp('FileUploader', {action: 'new'})

是否可以从Selenium中执行此操作?

Is there a way to execute this from Selenium?

推荐答案

WebDriver driver = new AnyDriverYouWant();

if (driver instanceof JavascriptExecutor)

{

((JavascriptExecutor)driver).executeScript("yourScript();");

}

这篇关于如何从Selenium中调用JavaScript函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆