2016-03-21 4 views

Antwort

1

Sie müssen auf ein Kontrollkästchen klicken, um die Zeile richtig auszuwählen? Ich nehme an, das ist, was Sie meinten: Der einzige Weg, wie ich weiß, ist, jede Zeile zu überprüfen, wählen Sie den Filter (d. H. Eine Kundennummer) und sobald Sie es finden, klicken Sie auf die Auswahlbox. Meistens die Tabellen sind so hier ähnlich ein Beispiel:

Das ist Ihre Tabelle:

=   =    =    =     =      =   = 
    ================================================================================================= 
    =   =    =    =     =      =   = 
    ================================================================================================= 
    =   =    =    =     =      =   = 
    ================================================================================================= 
    Lets say that in the first row, is where the checkbox is, and that in the second row is the location of the filter. 
    meaning the data you will use in order to know that this is the row you need.... 

    you will need to inspect the table element in order to find its ID, once you have that info you can use a similar method as the below: 
    Where you will use your webdriver, data filter, tableID and the number of the column where your data filter is located. 
    The method will return the row you need to click, then you can simply use the row[columnNumberLocation].Click() in order to select it. 

public IWebElement returnRow(IWebDriver webDriver, string filter ,string tableName, int i) 
    { 

     IWebElement tableElement = webDriver.FindElement(By.Id(tableName)); 
     IWebElement tbodyElement = tableElement.FindElement(By.TagName("TBODY")); 

     List<IWebElement> rows = new List<IWebElement>(tbodyElement.FindElements(By.TagName("tr"))); 

     foreach (var row in rows) 
     { 
      List<IWebElement> cells = new List<IWebElement>(row.FindElements(By.TagName("td"))); 

      if (cells.Count > 0) 
      { 
       string s = cells[i].Text; 
       if (s.Equals(filter)) 
       { 
        return row; 
       } 
      } 
     } 
     return null; 
    } 
0

Es hängt davon ab, was Ihre Anforderung, dass bestimmte Zeile auswählen.

Ich nehme an, dass Sie das entsprechend dem Zeilenindex auswählen müssen. Es geht also nur um den x-Pfad, um das Element zu finden.

Ex: Ich brauche Zeilennummer 2000

WebElement element = driver.findElement(By.xpath("//tr[2000]"));

zu erhalten
Verwandte Themen