开发者

How do you use Selenium to execute javascript within a frame?

开发者 https://www.devze.com 2022-12-29 07:19 出处:网络
I have a page (index.html) which has a frame: <html> <body> <iframe src=\"otherPage.html\" />

I have a page (index.html) which has a frame:

<html>
<body>
<iframe src="otherPage.html" />
</body>
</html>

And the otherPage.html has the contents:

<html>
<head><link src="jquery-min.js" type="text/javascript" /></head>
<body><div id="main">Contents</div></body>
</html>

I am attempting to use the following selenium c开发者_StackOverflowode on index.html:

selenium.open("index.html");
selenium.selectFrame("//iframe");
selenium.getEval("window.jQuery('div[id=main]')");

However this fails miserably. It says that the jQuery object doesn't exist.

If I attempt to execute the selenium test on the otherPage like so:

selenium.open("otherPage.html");
selenium.getEval("window.jQuery('div[id=main]')");

everything is hunky dory.

Right now this is pseudo code, if people want me to make it compile I'll do that and put it on github.


Selenium stores the Window Object within its own object so it can manipulate it better. Once you move to the frame it should be like this.

selenium.getEval("var window = this.browserbot.getUserWindow();window.jQuery('div[id=main]')");

And that should work for you

I have a tutorial on my site for this type of situation here


You can use :

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("javascript:sendEvent('play');");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号