How to find element in table

Best practices, code snippets for common functionality, examples, and guidelines.
IvanT
Posts: 51
Joined: Wed Feb 06, 2019 8:00 pm

How to find element in table

Post by IvanT » Thu Dec 26, 2019 6:35 pm

void ITestModule.Run()
{
Mouse.DefaultMoveTime = 60;
Keyboard.DefaultKeyPressTime = 30;
Delay.SpeedFactor = 1.0;
UserCodeMethods.ScrollToElement("/form[@name='ImportOprobFrm']/table[@name='PoleNameGr']/?/?/cell[@name='Fe общ.']",TestGeoTechRepository.Instance.ИмпортОпробованияШаг2Из3.PoleNameGr);

public static bool ScrollToElement(string pathToElement, Table table){
for( int i=0;i<table.Rows.Count;i++){
try{
if(Host.Local.FindSingle(pathToElement).Enabled)
{
return true;
}
}catch(ElementNotFoundException){
ScrollBar scrollBar= Таблица.FindChild<ScrollBar>();
scrollBar.FindSingle<Button>("button[@text='Down']").Click();
}
}
Report.Failure("Element'"+pathToElement+"' not founded");
return false;
}
}

method ScrollToElement recieves two parameters. firs is path to element which i am finding in table (second parametr) and it is work fine, but this code take a lot of code when i try to use it (too long line) and method is not comfortable to reuse, need path to file. i try to give this method first parameter Element (<cell>), but when test is running and element not founed, test failure with error.

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

Re: How to find element in table

Post by odklizec » Fri Dec 27, 2019 8:42 am

Hi.

Please uplaod a Ranorex snapshot (NOT screenshot) of given table plus complete xpath behind the repository element you are looking for. This would help us to understand your table and eventually, suggest the best approach. Thanks.

Without seeing the snapshot, all I can suggest is to use the page-up/down shortcut, instead of clicking on scrollbar button. It's just easier to implement and more reliable than clicking on scrollbar ;) On the other hand, scrollbar might be useful for determining how many times you need to scroll the table, to reach its start/end. But without seeing the snapshot, it's just a speculation.

PS: I just noticed you posted the snapshot in another thread. An sure enough, scrollbar min/max and value attributes could help you with determining, how many times you need to scroll to reach the end/start of the table.
ScrollBarMinMax.png
You do not have the required permissions to view the files attached to this post.
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