selectRowByValue
来源:互联网 发布:淘宝网注册步骤 编辑:程序博客网 时间:2024/06/10 14:50
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(); } }}