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

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

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

import org.junit.*;51Testing软件测试网 d|"TO"D^$g
import static org.junit.Assert.*;51Testing软件测试网1y8Db/`-~`(C^!D
import java.util.Date;51Testing软件测试网 m;l ]FO2i8?4U
import com.thoughtworks.selenium.*;51Testing软件测试网'uYT&_7Q ?A.z*k)\

/**51Testing软件测试网D*f:Wk o+kO]
* 自动发布宝贝51Testing软件测试网0f7Z:I9C C]
*/51Testing软件测试网p:i-\ M(su
public classTestAddBaibeiextends Search {

gb5p+B#tAeC051Testing软件测试网N"e hFupG6s!H^

public static Selenium localSelenium;

'V4c/M*y-g051Testing软件测试网:Bctj5kn%UL

@Before51Testing软件测试网 W^M5IBF!vkW hE,P"r
public void init() {
\&P \i,P;Y(u0localSelenium = selenium;
f8B-X]MY_8l*sn0}51Testing软件测试网6Q_A.^-H

n7rl0~)` ~0/**51Testing软件测试网 Ymg8{#f5P e
* 登录,填写宝贝信息,发布
J+{|~5X,[F ?5SS8S0*/51Testing软件测试网)\ R IW*hd
@Test51Testing软件测试网6Ax/Qo R i h
public void test_addBaobei(){
N9c2w(}]q&D0// 登录51Testing软件测试网,ier2Ni b7\
open(" http://login.taobao.com/member/login.jhtml ");
.m/j.n KdZV g0String xpath = "//input[@id='TPL_username_1']";
T`9XC4`8Erz0selenium.type(xpath, "c测试账号23");51Testing软件测试网Z-F^wVD
selenium.type("//input[@name='TPL_password']", "taobao1234");51Testing软件测试网lv"VSgj2nk5NKG
selenium.click("//button[@class='J_Submit']");51Testing软件测试网xS w6K3L*S3O
//Util.mySleep(5000);51Testing软件测试网:\Lr*l+l'}:PB

51Testing软件测试网es3o|6h r2[j

for(int i=1;i<100;i++){51Testing软件测试网9LF'C$P}1d;|Q
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");51Testing软件测试网i0O o$KeuUp.m6n
51Testing软件测试网,r2E+]~C3Y.@x
/*添加宝贝基本信息*/51Testing软件测试网c2SOK X:^
selenium.click ("//input[@id='on1']"); //全新51Testing软件测试网E;k'BW.r~e
selenium.select("//select[@id='prop_32731']", "商务休闲"); //风格51Testing软件测试网)|#i-hVB5v4PFa
//selenium.select("//select[@id='prop_6900399']", "嘻哈"); //风格细分
?a]5G r%\0selenium.type("//input[@name='_fma.pu._0.ti']","新宝贝"+i); //宝贝标题+i51Testing软件测试网7h7b6[6zk
selenium.type("//input[@name='_fma.pu._0.m']","2000"); //一口价
7@&Q[S ^4Cr0selenium.click("//input[@id='prop_20503_28383']"); //均码51Testing软件测试网U I2HOn*lE
selenium.type("//input[@id='sale_p_15']","2000"); //标准套餐价格
6} Z b {k9Hxq.G0selenium.type("//input[@id='sale_q_15']","1"); //标准套餐数量
"r'a/o8@eK)| Q9s0selenium.type("//input[@name='_fma.pu._0.q']","1"); //宝贝数量
;zJfE"Q0Util.mySleep(5000);51Testing软件测试网 N%Ynp"plq4U*z
selenium.click("//a[@data-detect='picSpace']"); //上传图片51Testing软件测试网@&_FN ]sx!w
selenium.click("//div[@id='J_List']/ul/li/a[@title='Asus华硕']"); //点击图片

;OxiL j @!@9GsK0

{4W8M*Gb&X8v8FZ$ZT0//selenium.type("//body[@class='ke-editor']","测试发表宝贝描述"); //宝贝描述.这样是添加不进富文本Iframe的,可用以下方法51Testing软件测试网e3Z1m*\%|k
selenium.selectFrame("//iframe[@title='kissy-editor']");51Testing软件测试网OB&CeK#p)oSI
selenium.getEval("selenium.browserbot.getCurrentWindow().document.body.innerHTML=\"测试发表宝贝描述\";");51Testing软件测试网t\ d [#xvC:Xq`2q
selenium.selectFrame("relative=up");
?T'E+CY.d+d zD4Kg0
Util.mySleep(10000);

0j o f nu`q051Testing软件测试网(r:idp4|:^P&R


u,{kTKN7F(c6flW0/*添加宝贝物流信息*/
3ZBx^w S3\0T.p/O1x0selenium.select("//select[@id='J_province']", "北京"); //所在地51Testing软件测试网/Q%Uhr@3yE
selenium.click("//input[@id='isApplyPostage_false']"); //运费
1nx"d e [0selenium.type("//input[@id='pyTF']","10"); //一口价
s|zC+g%s0selenium.type("//input[@id='kdTF']","15"); //标准套餐价格
9^td\ v+QR"} q0selenium.type("//input[@id='emsTF']","20"); //EMS51Testing软件测试网?qG2]a;Z
Util.mySleep(5000);51Testing软件测试网.gL&co*lp+o0u

.U7n*CTz051Testing软件测试网2M2m/TC"C"_%^6[
/* other info*/
(q6l"m#^)S xV]0selenium.click("//input[@id='durationId14']"); //有效期
P,Q6eO(dYh0selenium.click("//input[@id='event_submit_do_publish']");51Testing软件测试网`C vV ? zc DF(r$Q \
//Util.mySleep(5000);51Testing软件测试网 kG|U o
}51Testing软件测试网4?*^^)F(QK'Ga d`"W9q
}  

Gh3H}5xt0

TAG: Selenium selenium 自动化

 

评分:0

我来说两句

Open Toolbar