簡體   English   中英

在Selenium Webdriver中處理多頁表

[英]Handle multiple pages table in Selenium Webdriver

我進行了大量搜索,以找到用於在Selenium Webdriver中處理表格的示例。 所有示例僅針對僅5或10行的表進行說明。 我如何處理表格如打擊示例: https : //www.redmine.org/projects/redmine/issues
如何瀏覽此類表的所有頁面,例如獲取“主題”列的vlues?
簡單表的示例示例:
http://toolsqa.com/selenium-webdriver/handle-dynamic-webtables-in-selenium-webdriver/

這段代碼可能有效。 在這里,我得到所有問題的主題並將其打印在控制台中,您可以在內部for循環中編寫所需的任何assert語句。

driver.get("https://www.redmine.org//projects//redmine//issues");
    driver.manage().window().maximize();
    driver.findElement(By.xpath(".//*[@class='per-page']/a[2]")).click();
    int num_of_clicks = Integer.parseInt(driver.findElement(
            By.xpath(".//*[@id='content']/p[1]/a[3]")).getText());
    for (byte i = 1; i < num_of_clicks; i++) {
        List<WebElement> records_in_page = driver.findElements(By.xpath(".//*[@class='list issues']/tbody/tr"));
        for (byte j = 0; j < records_in_page.size(); j++) {
            String Issue_Subject = driver.findElement(
                    By.xpath(".//*[@class='list issues']/tbody/tr[" + (j+1)
                            + "]/td[5]")).getText();
            System.out.println(Issue_Subject);
        }
        driver.findElement(By.xpath(".//*[@class='next']")).click();
    }

感謝Krishna Reddy,這是給想要在C#中使用它的人提供的:

driver.Navigate().GoToUrl("https://www.redmine.org//projects//redmine//issues");
    driver.manage().window.maximize();
    driver.FindElement(By.XPath(".//*[@class='per-page']/a[2]")).click();
    int num_of_clicks = Int32.Parse(driver.FindElement(
            By.XPath(".//*[@id='content']/p[1]/a[3]")).Text);
    for (byte i = 1; i < num_of_clicks; i++) {
        IList<IWebElement> records_in_page = driver.FindElements(By.XPath(".//*[@class='list issues']/tbody/tr"));
        for (byte j = 0; j < records_in_page.Count; j++) {
            String Issue_Subject = driver.FindElement(
                    By.XPath(".//*[@class='list issues']/tbody/tr[" + (j+1)
                            + "]/td[5]")).Text;
            Console.WriteLine(Issue_Subject);
        }
        driver.FindElement(By.XPath(".//*[@class='next']")).click();
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM