新的硒。请帮忙。无法专注于当前帧

时间:2011-10-20 11:24:19

标签: selenium-ide

我正在从java代码处理selenium。在我当前的页面中有两个框架,我基本上想要在页面中的这两个框架中的任何一个框架中搜索文本。

现在,问题是当我到达此页面时,焦点似乎不会出现在新打开的页面上,因此也不会出现在其中的帧中。

我尝试了以下几个选项: 1. Selenium.SelectFrame(“relative = top”),index = 0/1,SelectFrame(“// frame”); 2.尝试selenium.getEval(“document.getElementsByTagName('frame')[0] .contentWindow.document”); 3.还尝试了带有名称/标题选项的selenium.selectWindow()。

我仍然无法将注意力集中在当前页面上,因此无法搜索预期的文本(我正在使用selenium.isTextPresent(“text”)),但它无法正常工作,因为我猜焦点它没有转移到框架/页面。

你能告诉我我错过了什么吗?

谢谢, 苏曼

1 个答案:

答案 0 :(得分:1)

Selenium无法搜索多个帧。如果要在任一帧中查找相同的字符串,则必须对两个搜索进行编码。例如:

main.html中:

<html>
    <frameset>
        <frame id="frame1" src="frame1.html">
        <frame id="frame2" src="frame2.jhtml">
    </frameset>
<html>

frame1.html:

<html>
    <body>
        <p>Hello from frame 1!</p>
    </body>
<html>

frame2.html:

<html>
    <body>
        <p>Hello from frame 2!</p>
    </body>
<html>

然后以下任何一帧都应该找到“Hello”:

foundHello = false;
selenium.selectFrame("relative=top");
selenium.selectFrame("id=frame1");
if selenium.isTextPresent("Hello") then foundHello = true;
selenium.selectFrame("relative=top");
selenium.selectFrame("id=frame2");
if selenium.isTextPresent("Hello") then foundHello = true;
if (foundHello) then ... blah blah blah ...