如何获取selenium中webtable的最后一行
我有一个webtable,我必须为它获取最后一行。问题是webtable是动态的,所以我不知道行号。我尝试了下面的代码,但行号是静态的,这将失败如何获取selenium中webtable的最后一行,selenium,Selenium,我有一个webtable,我必须为它获取最后一行。问题是webtable是动态的,所以我不知道行号。我尝试了下面的代码,但行号是静态的,这将失败 List<WebElement> rows=driver.findElements(By.xpath("//table[1]/tbody/tr[5]")); List rows=driver.findElements(By.xpath(“//table[1]/tbody/tr[5]”); 要获取最后一个元素,请使用(定位器)[last()
List<WebElement> rows=driver.findElements(By.xpath("//table[1]/tbody/tr[5]"));
List rows=driver.findElements(By.xpath(“//table[1]/tbody/tr[5]”);
要获取最后一个元素,请使用(定位器)[last()]
方法,如:
WebElement lastRow = driver.findElement(By.xpath("(//table[1]/tbody/tr)[last()]"));
它是以下的一种变体:
(locator)[position() = last()]
要获取最后一个元素,请使用
(locator)[last()]
方法,如:
WebElement lastRow = driver.findElement(By.xpath("(//table[1]/tbody/tr)[last()]"));
它是以下的一种变体:
(locator)[position() = last()]
int lastRowcount=driver.findElement(By.xpath(“//table[1]/tbody/”).findElements(By.tagName(“tr”)).size()
WebElement Lastrow=driver.findElement(By.xpath(“//表[1]/tbody/tr[“+lastRowcount+”])代码>
在第一行中,我们从表中获取最后一行计数
public class LastRowFetching {
public static void main(String[] args) throws ParseException {
WebDriver driver;
System.setProperty("webdriver.chrome.driver","G://chromedriver.exe");
driver= new ChromeDriver();
driver.get("http://money.rediff.com/gainers/bsc/dailygroupa?");
//No.of rows
List rows = driver.findElements(By.xpath(".//*[@id='leftcontainer']/table/tbody/tr/td[1]"));
System.out.println("No of rows are : " + rows.size());
int lastRow = rows.size();
WebElement lastRowFetch =driver.findElement(By.xpath(".//*[@id='leftcontainer']/table/tbody/tr/td["+lastRowcount+"])"));
driver.close();
}
}
在第二行,我们从表中获取最后一行元素。int lastRowcount=driver.findElement(By.xpath(“//table[1]/tbody/”)).findElements(By.tagName(“tr”).size()
public class LastRowFetching {
public static void main(String[] args) throws ParseException {
WebDriver driver;
System.setProperty("webdriver.chrome.driver","G://chromedriver.exe");
driver= new ChromeDriver();
driver.get("http://money.rediff.com/gainers/bsc/dailygroupa?");
//No.of rows
List rows = driver.findElements(By.xpath(".//*[@id='leftcontainer']/table/tbody/tr/td[1]"));
System.out.println("No of rows are : " + rows.size());
int lastRow = rows.size();
WebElement lastRowFetch =driver.findElement(By.xpath(".//*[@id='leftcontainer']/table/tbody/tr/td["+lastRowcount+"])"));
driver.close();
}
}
WebElement Lastrow=driver.findElement(By.xpath(“//表[1]/tbody/tr[“+lastRowcount+”])代码>
在第一行中,我们从表中获取最后一行计数
public class LastRowFetching {
public static void main(String[] args) throws ParseException {
WebDriver driver;
System.setProperty("webdriver.chrome.driver","G://chromedriver.exe");
driver= new ChromeDriver();
driver.get("http://money.rediff.com/gainers/bsc/dailygroupa?");
//No.of rows
List rows = driver.findElements(By.xpath(".//*[@id='leftcontainer']/table/tbody/tr/td[1]"));
System.out.println("No of rows are : " + rows.size());
int lastRow = rows.size();
WebElement lastRowFetch =driver.findElement(By.xpath(".//*[@id='leftcontainer']/table/tbody/tr/td["+lastRowcount+"])"));
driver.close();
}
}
在第二行,我们从表中得到最后一行元素。您能给我们一个示例URL吗?谢谢你能给我们一个样本网址吗?谢谢你可以用一点文字和解释来扩展你的答案。。。在这种情况下,这根本没有什么帮助。也许你可以用一点文字和解释来扩展你的答案。。。在这种情况下,这根本没有什么帮助。
public class LastRowFetching {
public static void main(String[] args) throws ParseException {
WebDriver driver;
System.setProperty("webdriver.chrome.driver","G://chromedriver.exe");
driver= new ChromeDriver();
driver.get("http://money.rediff.com/gainers/bsc/dailygroupa?");
//No.of rows
List rows = driver.findElements(By.xpath(".//*[@id='leftcontainer']/table/tbody/tr/td[1]"));
System.out.println("No of rows are : " + rows.size());
int lastRow = rows.size();
WebElement lastRowFetch =driver.findElement(By.xpath(".//*[@id='leftcontainer']/table/tbody/tr/td["+lastRowcount+"])"));
driver.close();
}
}