23.9 C
New York
Thursday, September 5, 2024

automated testing – Clicking a cell in a dynamic knowledge desk C# WebDriver


The HTML I am attempting working with is under,

Clicking the under opens a modal window however I am struggling to get the clicking to work,

Because the desk is dynamic I do not suppose I can use the XPath, the code at current seems like this,

driver.FindElement(By.ClassName("cell-popover")).Click on();

Which works nice so long as the cell is on the primary row of the desk, nevertheless this is not going to all the time be the case so would love some advicehelp on methods to proceed?

UPDATE

Solved it with this,

IWebElement elemTable = driver.FindElement(By.Id("enquiry-header-grid-SalesTransactionEnquiry-enquiry-header-grid-wrapper")).FindElement(By.TagName("tbody"));
Record lstTrElem = new Record(elemTable.FindElements(By.TagName("tr")));
IWebElement row = lstTrElem.The place(merchandise => merchandise.Textual content.Accommodates("LU1")).FirstOrDefault();
string rowid = row.GetAttribute("data-uid");
IList cells = row.FindElements(By.TagName("td"));
for (int i = 0; i < cells.Rely; i++)
{
    IWebElement cell = cells[i];
}
row.FindElement(By.ClassName("cell-popover")).Click on();

Because the td containing "LU1" is all the time distinctive, be intersted to know if there's a extra efficientreliable means of doing it although!

Second Replace

Refined it barely to the next,

IWebElement elemTable = driver.FindElement(By.Id("enquiry-header-grid-SalesTransactionEnquiry-enquiry-header-grid-wrapper")).FindElement(By.TagName("tbody"));
Record lstTrElem = new Record(elemTable.FindElements(By.TagName("tr")));
IWebElement row = lstTrElem.The place(merchandise => merchandise.Textual content.Accommodates("LU1")).FirstOrDefault();
string rowid = row.GetAttribute("data-uid");
row.FindElement(By.ClassName("cell-popover")).Click on();

Appears to be dependable

5

  • both By.LinkText("MUFC") or By.CssSelector("[data-col-name='ST_COPYCUST']") or By.XPath("//a[normalize-space()='MUFC']"). You might want to make use of a waiter if the content material is created dynamically.


    Commented
    Mar 15, 2018 at 18:48

  • The issue with these approaches is that the LinkText "MUFC" for that column is not going to be distinctive so i must specify the row to seek out the LinkText in - I used to be considering of attempting to make use of the


Commented
Mar 15, 2018 at 23:37



  • What's the precise error you're getting in different dynamic circumstances?


    Commented
    Mar 16, 2018 at 7:35

  • As I perceive , there is just one hyperlink going to be in any case within the desk (solely row can differ),if sure then object is exclusive so what's the subject right here?


    Commented
    Mar 16, 2018 at 7:37



  • Glad to shut this as my implementation appears dependable, thanks for the feedback and solutions!!


    Commented
    Mar 16, 2018 at 19:06

  • MUFC Manchester United 23/10/2017 1 Bill 1000 5.00 1.00 SA 6.00 0.00 2017 1 23/10/2017 23/10/2017 0.00
    MUFC

    Related Articles

    LEAVE A REPLY

    Please enter your comment!
    Please enter your name here

    Latest Articles