2017-03-22 7 views
-1

Selenium webdriverでテーブルを扱うサンプルを探すために、たくさん検索しました。すべてのサンプルは、わずか5行または10行の表についてのみ説明しています。どのように私はテーブルのようなテーブルを扱うことができます: https://www.redmine.org/projects/redmine/issues
私はどのようにこれらの種類のテーブルのすべてのページを通過し、 "件名"列の例を得ることができますか?
簡易テーブルのサンプル例:
http://toolsqa.com/selenium-webdriver/handle-dynamic-webtables-in-selenium-webdriver/Selenium Webdriverで複数のページテーブルを処理する

+0

次のようにあなたには、いくつかの詳細を提供することができます:1.あなたの目的は何ですが?あなたは何をしようとしていますか? 3.あなたはまだ何を試しましたか? 4.あなたのために働いたのは何ですか?コードを表示する。あなたはどこにいますか? – DebanjanB

答えて

2

このコードは動作する可能性があります。ここで私はすべての問題の件名を取得し、コンソールでそれを印刷している、あなたは内側のループで必要なすべてのアサート文を書くことができます。

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(); 
    } 
+0

素晴らしい。ありがとうございます –

+0

ちょうど1つの問題は、最後のページで私はちょうど1つのデータを持っているので、プログラムはそれ以降の任意の要素を見つけることができないと私は例外を取得します。これをどうすれば処理できますか? –

+0

の代わりに2番目のforループで100の代わりに各ページのテーブルのサイズを保持します。 –

1

クリシュナレディのおかげで、これは、誰かが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(); 
    } 
関連する問題