最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to call a JavaScript function from within Selenium? - Stack Overflow

programmeradmin3浏览0评论

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'})

Is there a way to execute this from Selenium?

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'})

Is there a way to execute this from Selenium?

Share Improve this question edited Nov 21, 2014 at 18:54 Sebastian Zartner 20.1k10 gold badges102 silver badges141 bronze badges asked Nov 21, 2014 at 9:02 bpkbpk 3132 gold badges6 silver badges20 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 11

Try this:

WebDriver driver = new ChromeDriver();
((JavascriptExecutor)driver).executeScript("yourScript();");
WebDriver driver = new AnyDriverYouWant();

if (driver instanceof JavascriptExecutor)

{

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

}
发布评论

评论列表(0)

  1. 暂无评论