2016-03-21 2 views

ответ

1

Вы должны нажать на флажок, чтобы выбрать строку справа? Я предполагаю, что вы имели в виду: Единственный способ, которым я знаю, как проверять каждую строку, выбирать фильтр (т. Е. Номер клиента), и как только вы его найдете, установите флажок выбора. В основном из таблиц похожи, так вот пример:

Это ваш стол:

=   =    =    =     =      =   = 
    ================================================================================================= 
    =   =    =    =     =      =   = 
    ================================================================================================= 
    =   =    =    =     =      =   = 
    ================================================================================================= 
    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

Это зависит от того, что ваше требование выбора этой конкретной строки.

Я предполагаю, что вам нужно выбрать это в соответствии с индексом строки. Итак, это все о вашем пути х, чтобы найти элемент.

например: мне нужно, чтобы получить номер строки 2000

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