Select a row from the table and then click t he subsequent delete button from the same row

Ask general questions here.
premravi
Posts: 69
Joined: Tue Jan 08, 2019 1:55 pm

Select a row from the table and then click t he subsequent delete button from the same row

Post by premravi » Mon Apr 15, 2019 3:27 pm

Hi,

I am automating a scenario wherein I have a select a row from the table and I am selecting using the innertext as it is present inside the span element
(Please refer to the screenshot attached)
And then I have to click on the delete button for the same row
But every time the image which I have to click will be different everytime so we cannot hardcode it on the basis of row number, that's the reason I am selecting the row based on the innertext of the row because the name of the image will always be same
So, basically I am looking for a solution like whatever row I am selecting using innertext the subsequent delete button should be clicked for the same row
Please refer to the screenshot attached and the snapshot

Please let me know if I did not made my point my clear
Attachments
TableRootSnapshot.rxsnp
(119.43 KiB) Downloaded 7 times
DeleteRow.png
DeleteRow.png (10.86 KiB) Viewed 158 times

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 4924
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Select a row from the table and then click t he subsequent delete button from the same row

Post by odklizec » Tue Apr 16, 2019 7:13 am

Hi,

The xpath you are looking for looks like this:

Code: Select all

/dom[@domain='dashboard.eu-iport.nielsen-iwatch.com.aws-w-np.nielsencsp.com']//div[@class='edit-view-container']//div[@class='left-panel-container']//div[@class='mj-treegrid-container']//table/tbody//div[@class~'mj-text']/span[@innertext='Automation.jpg']/ancestor::tr//a[@class='delete']
All you need to do is to replace 'Automation.jpg' with variable of your choice, ideally filled with data connector.

I would also suggest you to watch this webinar about mastering xpaths:
https://www.ranorex.com/automated-testi ... norexpath/
And make sure to read and understand these user guide chapters:
https://www.ranorex.com/help/latest/ran ... roduction/
https://www.ranorex.com/help/latest/ran ... roduction/
Understanding Ranorex xpaths is the most essential part of Ranorex knowledge. Without deep understanding of xpaths, how to construct them and how to use relationship operators, your Ranorex time will be more a guess work. So give it a time to learn it and understand it ;) Good luck!
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

premravi
Posts: 69
Joined: Tue Jan 08, 2019 1:55 pm

Re: Select a row from the table and then click t he subsequent delete button from the same row

Post by premravi » Wed Apr 17, 2019 10:01 am

Hi,

Thanks a lot for this information,

It really helped,

Just out of curiosity I am asking, in case if there are two a[@class='delete'] a tags in the same row then it will click on the first ancestor how to make it click on the second ancestor?

Thanks for sharing the recordings also, I will definitely go through it to improve my xpath designing skills

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 4924
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Select a row from the table and then click t he subsequent delete button from the same row

Post by odklizec » Wed Apr 17, 2019 11:27 am

Hi,

In case there are two a[@class='delete'] tags in the same row, and you wan to click just the second one, you have to add an index at the end of A tag, like this:
./ancestor::tr//a[@class='delete'][2]
Eventually, you can use this, to tell Ranorex to click the 'last one' in the list of returned elements (just in case there may be three, four, or 'n' elements and you want to click the LAST one):
./ancestor::tr//a[@class='delete'][-1]
However, if you want to click both first and second delete A tag, you will have to construct some code for this. For an example of code, which creates list of adapters from repo info element, and which click each found element, check this paragraph:
https://www.ranorex.com/help/latest/han ... oryelement

In your case, the code should look like this:

Code: Select all

public void ClickAllDeleteButtonsInTheSameRow(RepoItemInfo elementFromRepo)
{
    // Create a list of adapters using the "Info" object
    IList<Ranorex.ATag> buttonList = elementFromRepo.CreateAdapters<Ranorex.ATag>();
    // Move the mouse pointer to each button of the list and click it
    foreach (Ranorex.ATag button in buttonList )
    {
        button.Click();
    }
}
Where the elementFromRepo argument should be assigned with repo element, pointing to the xpath I provided before (without index at the end of xpath). Hope this helps?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration