selectRowByValue

 
package com.test;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import com.Bam.SeleniumSigleInstance;
import com.myexception.MyException;
import com.thoughtworks.selenium.Selenium;
import com.controltype.TextBox;

;
public class TestTextboxandTextArea
{
 private static Selenium selenium;
 private TextBox tb = new TextBox();
 private String path = "http://localhost:8080/webTest/js/TextArea.html";
 int pRow = 0;
 int pColumn = 0;

 // private Selenium selenium1;

 @BeforeClass
 public static void setUp() throws Exception
 {

  selenium = SeleniumSigleInstance.getInstance();

 }

 /*
  * //
  * 
  * @AfterClass public static void tearDown() throws Exception {
  * selenium.stop(); }
  */
 public int getRowByValue(String Key, String xpath)
 {
  int row = (Integer) selenium.getXpathCount(xpath + "//tr");
  int column = (Integer) selenium.getXpathCount(xpath + "//td");
  column=column/row;
  
  System.out.println(row);
  System.out.println(column);
  for (int i = 1; i < row; i++)
  {
   for (int j = 1; j < column; j++)
   {
    String tableXpath = xpath + "//tr" + "[" + i + "]" + "/td[" + j
      + "]";
    if (Key.equals(selenium.getText(tableXpath)))
    {
     pRow = i;
     System.out.println(pRow);
     return pRow;
    }

   }
  }
   return -1;
 }

 @Test
 public void testTextBoxAndTextArea() throws InterruptedException
 {
  // selenium.open("C:\\jack\\d\\workspace\\BamSelenium\\src\\com\\testpages\\TextArea.html");
  selenium.open(path);
  Thread.sleep(3000);
  try
  {
   /*
    * tb.setVaule("//textarea[@name='ta']", "testeststststastastsatt");
    * tb.setVaule("//input[@name='tb1']", "tstatttttt");
    * tb.setVaule("//input[@name='tb2']", "tstatttttt");
    */
   // selenium.click("//table[@id='tbtest']//tr[3]/td/a");
   // selenium.click("//a[contains(@href,'baidu')]");
   // selenium.click("//a[@href='http://www.baidu.com']");
   int row=getRowByValue("google7", "//table[@id='tbtest']");
   selenium.click("//table[@id='tbtest']"+"//tr["+row+"]/td["+5+"]/a");

  }
  catch (Exception e)
  {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }

}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值