已转开发,博客新地址:http://welcomezhang.iteye.com/

解决Selenium无法type富文本的问题

上一篇 / 下一篇  2011-08-06 13:39:33 / 个人分类:自动化测试

import org.junit.*;
_ZnXyO0import static org.junit.Assert.*;51Testing软件测试网]B }}i2?)A.i
import java.util.Date;
+sHo`"u3v,c K'N0import com.thoughtworks.selenium.*;51Testing软件测试网[G'x3SS

/**51Testing软件测试网t)z] fa$AW"^
* 自动发布宝贝51Testing软件测试网{ }9C.iR:t
*/51Testing软件测试网l2fi*o!]eR#_3s/}
public classTestAddBaibeiextends Search {

"IA A"M-A_cm0

1u)z:L2\\"w3v0public static Selenium localSelenium;

$V6_j'wQ/h;a,`}0

F1fSCXDX-rI7kK@0@Before
!UYo&W1c6g]\0public void init() {
*n1e`ji K UH ?|s0localSelenium = selenium;51Testing软件测试网"x$Kfuw?Z/y|t8_/j`
}51Testing软件测试网b _eUUsq

6^[xoC0/**
.f:{E.J7Ee h0* 登录,填写宝贝信息,发布
uT `T,i0Q2~,tJ0*/
*FFdC;s)^"p8vY0@Test51Testing软件测试网 t z:l+gw5^-[
public void test_addBaobei(){51Testing软件测试网+QAv;qo*RUJr xY
// 登录51Testing软件测试网6T0D}-L$I"m1uR
open(" http://login.taobao.com/member/login.jhtml ");51Testing软件测试网X~m/tF ]4XT
String xpath = "//input[@id='TPL_username_1']";
)oo9Qm5\6h,FO(g0selenium.type(xpath, "c测试账号23");51Testing软件测试网"cI*s X }y/J
selenium.type("//input[@name='TPL_password']", "taobao1234");
wl:F?j,Yi0selenium.click("//button[@class='J_Submit']");51Testing软件测试网\?&M8E]*^
//Util.mySleep(5000);51Testing软件测试网)\yS.u4N5Hi7V

0e#QUNX`0for(int i=1;i<100;i++){51Testing软件测试网vFu SC
open(" http://upload.taobao.com/auction/publish/publish_by_spu.htm?spu_id=93088587&auction_type=b&auction_id=&item_num_id=10588813056&wirelessOption=&wirelessmpChoosed=&isEdit=false");
A/d5{6\Jc.\0
B2v.s,rSA*L%YQ$G0/*添加宝贝基本信息*/51Testing软件测试网0o{Aj6Z$v$L
selenium.click ("//input[@id='on1']"); //全新
zNH:FN)K0selenium.select("//select[@id='prop_32731']", "商务休闲"); //风格51Testing软件测试网h:K8BvkWc4d1m
//selenium.select("//select[@id='prop_6900399']", "嘻哈"); //风格细分51Testing软件测试网1R&LV"Urm
selenium.type("//input[@name='_fma.pu._0.ti']","新宝贝"+i); //宝贝标题+i
Z L2z4e"E\q0selenium.type("//input[@name='_fma.pu._0.m']","2000"); //一口价
z {U wX0selenium.click("//input[@id='prop_20503_28383']"); //均码
J ?l]u0k0selenium.type("//input[@id='sale_p_15']","2000"); //标准套餐价格51Testing软件测试网!D3],PD%Zg7f@
selenium.type("//input[@id='sale_q_15']","1"); //标准套餐数量
1Gk,U*YL ]pwE0selenium.type("//input[@name='_fma.pu._0.q']","1"); //宝贝数量
5R \ [9gW1p.xR0Util.mySleep(5000);
P:I9OAL?0selenium.click("//a[@data-detect='picSpace']"); //上传图片51Testing软件测试网 JX W*J0km
selenium.click("//div[@id='J_List']/ul/li/a[@title='Asus华硕']"); //点击图片51Testing软件测试网+~7L'u TkO"Y4E

51Testing软件测试网WF8o)u:n'Ov

//selenium.type("//body[@class='ke-editor']","测试发表宝贝描述"); //宝贝描述.这样是添加不进富文本Iframe的,可用以下方法51Testing软件测试网C8zH)SrO
selenium.selectFrame("//iframe[@title='kissy-editor']");
IAf:|u0_0selenium.getEval("selenium.browserbot.getCurrentWindow().document.body.innerHTML=\"测试发表宝贝描述\";");
'YI&M8m-y8nfc0selenium.selectFrame("relative=up");51Testing软件测试网6NB T0S)sR
Util.mySleep(10000);51Testing软件测试网%g/J-}f Uv1F-S `

51Testing软件测试网5@6@^$hXV0Uf*l

51Testing软件测试网8eW8Z+]C-vSe
/*添加宝贝物流信息*/
!p7r w2uVN}lwK0selenium.select("//select[@id='J_province']", "北京"); //所在地51Testing软件测试网 ?6Yl{,]%B9@k(~!r
selenium.click("//input[@id='isApplyPostage_false']"); //运费51Testing软件测试网 Ya a~w/`4i5KNr
selenium.type("//input[@id='pyTF']","10"); //一口价
8i:p!y:U6Mp/~0selenium.type("//input[@id='kdTF']","15"); //标准套餐价格51Testing软件测试网ib o;_*aK-kj t
selenium.type("//input[@id='emsTF']","20"); //EMS51Testing软件测试网"Q(M1~8~HK'm
Util.mySleep(5000);

Ab.E+J,hq e"i0

c,B c|4g9J1U051Testing软件测试网@%\"Q;NlL;cu
/* other info*/51Testing软件测试网 _mp,W)l@K(\
selenium.click("//input[@id='durationId14']"); //有效期51Testing软件测试网w1J zJfO"~l
selenium.click("//input[@id='event_submit_do_publish']");51Testing软件测试网WQ&EE:y5_/yD%@
//Util.mySleep(5000);
6t.S;zBHf!H%E&oH%x0}
H/}C.^8R X0}  51Testing软件测试网Zr2g,z({)}X?2_


TAG: Selenium selenium 自动化

 

评分:0

我来说两句

Open Toolbar