Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to auto scroll in table #59

Open
ManikandanSuryaprakasam opened this issue Jul 20, 2022 · 4 comments
Open

Not able to auto scroll in table #59

ManikandanSuryaprakasam opened this issue Jul 20, 2022 · 4 comments

Comments

@ManikandanSuryaprakasam
Copy link

ManikandanSuryaprakasam commented Jul 20, 2022

Hi Gary
I'm able to click and read values of the cell elements in a table.But when the table has more number of records and some of the records not visible in UI and table displayed with a vertical scroll bar.At that time when I try to read the values of jabelement application crashes.
Is there any way to read the values of these invisible jab elements by scrolling automatically? I'm using below method to get all jab elements but limited to only visible elements.

def table_click(self, tabl, value):
    info = tabl._get_visible_children()
    # print(info)
    # To get the row and column count
    tableinfo = tabl.get_element_information()
    # print(type(tableinfo))
    # print(tableinfo["table"]["row_count"])
    row = tableinfo["table"]["row_count"]
    # print(tableinfo["table"]["column_count"])
    col = tableinfo["table"]["column_count"]
    result = tabl.bridge.getVisibleChildren(tabl.vmid, tabl.accessible_context, 0, byref(info))
    cellcount = 0
    values = []
    elements = []
    valuelist = [[]]
    elementlist = [[]]
    # To Store the value in a list of list

    # print(JABElement(tabl.bridge, tabl.hwnd, tabl.vmid, info.children[1]).get_element_information()['name'])
    for incr in range(0, ((row * col) - 1)):
        values.insert(incr, JABElement(tabl.bridge, tabl.hwnd, tabl.vmid,
                                       info.children[cellcount]).get_element_information()["name"])
        elements.insert(incr, JABElement(tabl.bridge, tabl.hwnd, tabl.vmid,
                                         info.children[cellcount]))
        cellcount = cellcount + 1
    # print(cellcount)
    # print(values)
    # print(elements)
    d = dict(zip(elements, values))

    for x in d:
        if d[x] == value:
            x.click(simulate=True)
    time.sleep(3)
@gaozhao1989
Copy link
Owner

gaozhao1989 commented Jul 28, 2022

Hi @ManikandanSuryaprakasam,

Thanks for your feedback.
I have to try your scenarios, actually there is no necessary scroll to cell when you try to get invisible cell element from table.
here is the sample:

jab = JABDriver("TableListSelectionDemo")
table = jab.find_element_by_role("table")
print(table.get_cell(6,0).get_element_information())

this can get cell information.

Back to your question about scroll action in table.
There is no JAB API support for scroll bar handle action, for this scenario Pyjab use mouse action simulate the scroll, that may does not work in table. Comment from Oracle as below:

Tracking Values of GUI Elements: Use the AccessibleValue support and Value PropertyChange events to track the values of GUI elements like sliders and scroll bars.

You can also reference with this URL: https://docs.oracle.com/en/java/javase/17/access/java-access-bridge-api.html

@szczepanR
Copy link

Hi @ManikandanSuryaprakasam,
I faced a similar problem. I have a workaround. The idea is simple, just scroll some rows (up or down) and check whether the wanted row is visible, see below

def select_jqm_row(row_number: int):
   try:
       jabdriver = JABDriver("Javaapp")
       all_jobs_tab = jabdriver.find_element_by_name("All jobs")
       table = all_jobs_tab.find_element_by_role("table")
       table_info = table.get_element_information()
       row_count = table_info["table"]["row_count"]
       column_count = table_info["table"]["column_count"]
       if row_count < row_number:
           print("Row number ", row_number, " is outside the row count ", row_count)
           return False
       scroll_bar = all_jobs_tab.find_element_by_role("scroll bar", visible=True)
       cell_id = (row_number - 1) * column_count
       info = VisibleChildrenInfo()
       visible_children_count = table.bridge.getVisibleChildrenCount(table.vmid, table.accessible_context, 0,
                                                                     byref(info))
       counter = 0
       # 5 times try to check if a wanted row is visible
       while counter < 5:
           result = table.bridge.getVisibleChildren(table.vmid, table.accessible_context, 0, byref(info))
           first_visible_cell = JABElement(table.bridge, table.hwnd, table.vmid,
                                           info.children[0])
           last_visible_cell = JABElement(table.bridge, table.hwnd, table.vmid,
                                          info.children[visible_children_count - 1])
           first_visible_cell_info = first_visible_cell.get_element_information()
           last_visible_cell_info = last_visible_cell.get_element_information()
           index_in_parent_first_visible_cell = first_visible_cell_info["index_in_parent"]
           index_in_parent_last_visible_cell = last_visible_cell_info["index_in_parent"]
           if index_in_parent_first_visible_cell > cell_id:
               scroll_bar.scroll(to_bottom=False, hold=0.25)
           elif index_in_parent_last_visible_cell < cell_id:
               scroll_bar.scroll(hold=0.25)
           else:
               break
           counter += 1
           print("Could not find wanted row after 5 tries")
       visible_counter = 0
       while visible_counter < visible_children_count:
           visible_cell = JABElement(table.bridge, table.hwnd, table.vmid,
                                     info.children[visible_counter])
           visible_cell_info = visible_cell.get_element_information()
           index_in_parent_visible_cell = visible_cell_info["index_in_parent"]
           if index_in_parent_visible_cell == cell_id:
               visible_cell.click(simulate=True)
               return visible_cell
           visible_counter += 1
   except (JABException, TimeoutError) as e:
       print("select_jqm_row function failed with error:", e)
       pass

@ManikandanSuryaprakasam
Copy link
Author

Hi @ManikandanSuryaprakasam,

Thanks for your feedback. I have to try your scenarios, actually there is no necessary scroll to cell when you try to get invisible cell element from table. here is the sample:

jab = JABDriver("TableListSelectionDemo")
table = jab.find_element_by_role("table")
print(table.get_cell(6,0).get_element_information())

this can get cell information.

Back to your question about scroll action in table. There is no JAB API support for scroll bar handle action, for this scenario Pyjab use mouse action simulate the scroll, that may does not work in table. Comment from Oracle as below:

Tracking Values of GUI Elements: Use the AccessibleValue support and Value PropertyChange events to track the values of GUI elements like sliders and scroll bars.

You can also reference with this URL: https://docs.oracle.com/en/java/javase/17/access/java-access-bridge-api.html

Thanks !!! @gaozhao1989 , I'm able to get the invisible values and verify it using the above code.

@ManikandanSuryaprakasam
Copy link
Author

Hi @ManikandanSuryaprakasam, I faced a similar problem. I have a workaround. The idea is simple, just scroll some rows (up or down) and check whether the wanted row is visible, see below

def select_jqm_row(row_number: int):
   try:
       jabdriver = JABDriver("Javaapp")
       all_jobs_tab = jabdriver.find_element_by_name("All jobs")
       table = all_jobs_tab.find_element_by_role("table")
       table_info = table.get_element_information()
       row_count = table_info["table"]["row_count"]
       column_count = table_info["table"]["column_count"]
       if row_count < row_number:
           print("Row number ", row_number, " is outside the row count ", row_count)
           return False
       scroll_bar = all_jobs_tab.find_element_by_role("scroll bar", visible=True)
       cell_id = (row_number - 1) * column_count
       info = VisibleChildrenInfo()
       visible_children_count = table.bridge.getVisibleChildrenCount(table.vmid, table.accessible_context, 0,
                                                                     byref(info))
       counter = 0
       # 5 times try to check if a wanted row is visible
       while counter < 5:
           result = table.bridge.getVisibleChildren(table.vmid, table.accessible_context, 0, byref(info))
           first_visible_cell = JABElement(table.bridge, table.hwnd, table.vmid,
                                           info.children[0])
           last_visible_cell = JABElement(table.bridge, table.hwnd, table.vmid,
                                          info.children[visible_children_count - 1])
           first_visible_cell_info = first_visible_cell.get_element_information()
           last_visible_cell_info = last_visible_cell.get_element_information()
           index_in_parent_first_visible_cell = first_visible_cell_info["index_in_parent"]
           index_in_parent_last_visible_cell = last_visible_cell_info["index_in_parent"]
           if index_in_parent_first_visible_cell > cell_id:
               scroll_bar.scroll(to_bottom=False, hold=0.25)
           elif index_in_parent_last_visible_cell < cell_id:
               scroll_bar.scroll(hold=0.25)
           else:
               break
           counter += 1
           print("Could not find wanted row after 5 tries")
       visible_counter = 0
       while visible_counter < visible_children_count:
           visible_cell = JABElement(table.bridge, table.hwnd, table.vmid,
                                     info.children[visible_counter])
           visible_cell_info = visible_cell.get_element_information()
           index_in_parent_visible_cell = visible_cell_info["index_in_parent"]
           if index_in_parent_visible_cell == cell_id:
               visible_cell.click(simulate=True)
               return visible_cell
           visible_counter += 1
   except (JABException, TimeoutError) as e:
       print("select_jqm_row function failed with error:", e)
       pass

Hi @szczepanR .This code will be helpful to click the cell element. Will get back to you for any clarification once i try this code. Thanks !!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants