selenium.selectFrame()方法掌握

我们有个日志发表功能,几乎所有的网站都有,我们网站日志的编辑框是一个内嵌的iframe,用selenium录制脚本的时候,发现检索不到,导致日志根本没有办法提交,下图是我们网址日志的截图

之后,找到了selenium.selectFrame()方法,但是网站的"发表"按钮并不在iframe里面,所有就一直找不到“发表”按钮,测试通不过啊,终于上网找啊找,终于找到一个方法,其实很简单,但是由于对selenium的方法还不熟悉,所以还是花了不少时间的。

代码如下:

 

package com.jiaoyu;

 

import com.thoughtworks.selenium.*;

import org.junit.After;

import org.junit.Before;

import org.junit.Test;

import java.util.regex.Pattern;

 

public class Iframe extends SeleneseTestCase {

 

@Before

public void setUp() throws Exception {

selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://jiaxiaoquan.staff.139.com/");

selenium.start();

}

 

@Test

public void testIframe() throws Exception {

selenium.open("/webroot/apps/blog/index.php?s=/Index/addBlog");

this.login();

selenium.type("title", "测试iframe");

selenium.selectFrame("//iframe[@class='ke-iframe']");

selenium.type("//body[@class='ke-content']", "一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十");

selenium.selectFrame("relative=top");  //关键在于这一句了 selenium.selectFrame("relative=up");

selenium.click("//input[@value='发 表']");

selenium.waitForPageToLoad("30000");

}

 

 

public void login(){

String username = "13948895822";

String passwd = "111111";

selenium.type("mobile", username);

selenium.type("passwd", passwd);

selenium.click("//input[@value='登 录']");

selenium.waitForPageToLoad("30000");

}

 

 

@After

public void tearDown() throws Exception {

selenium.stop();

}

}

这篇文章对selenium.selectFrame()方法讲的很清晰:http://www.testingexcellence.com/accessing-iframe-data-with-selenium-rc/

 

IFrame: By Name: selenium.selectFrame(“mainFrame”); //name of the IFrame

By DOM: selenium.selectFrame(“dom=window.frames[1]“); //second IFrame By Index:selenium.selectFrame(“index=1″); //second IFrame

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值