Generated web content and chained locators


I’m working on a project where I need to interact with a web-based application. In this application i need to locate a button denoted “>” in order to expand a section of the page. The problem I’m facing is that this button has no unique attributes that I can use to pin point it.

The application has one row for each day of the month for the current time period (i.e. current month). So each row in the table contains three columns. The first one the date (yyyy-MM-dd) and day of week, the second one is empty, and the third one contains the button/link I need to click (with name attribute = ‘UNCOMPRESS’).

In order to solved this I am looking to use the RPA Browser Selenium library and the chained locators functionality. I have used the Selenium Firefox extension to calculate the locators. The resulting code is:

Wait And Click Button xpath=//b[contains(.,‘2023-09-01’)] >> xpath=//input[@name=‘UNCOMPRESS’]

This works fine for the first row in the timeperiod (2023-09-01), but when I update the date in the first locator to e.g. 2023-09-03 the robot still clicks on the link on the row with date 2023-09-01. It is as if the first part of the locator is completly ignored and the first input found with name = ‘UNCOMPRESS’ is selected.

Have I completly missinterpreted how the chained locator functionality works or am I missing something?

Hello and welcome to forum :wave: At glance locator looks like it should work. Are you also able to share relevant code?

@raivo Thanks! I have included a redacted version of my code below.

*** Settings ***
Documentation Navigate to website and enter time report data.

Library RPA.Browser.Selenium auto_close=${FALSE}
Library RPA.HTTP

*** Task ***
Navigate and report
Navigate to Site
Navigate to Time Report

*** Keywords ***
Navigate to Site
Open Browser

Wait Until Page Contains Element xpath=//input[@name=‘USERNAME’]
Input Text xpath://input[@name=‘USERNAME’] <removed_from_example>
Input Text xpath://input[@name=‘PASSWORD’] <removed_from_example>
Click Button xpath://input[@name=‘ACTION’]

Navigate to Time Report
Wait And Click Button xpath://div[@id=‘main’]/table/tbody/tr[5]/td[5]/form/input[2]
Wait And Click Button css=.listRowOdd:nth-child(4) > td:nth-child(6) .buttonSmall
#Below is the code that chooses the wrong link
Wait And Click Button xpath=//b[contains(.,‘2023-09-04’)] >> xpath=//input[@name=‘UNCOMPRESS’]

I have also included an image of the page source code.

Looking at the html I’m surprised that it would work on the first row. I believe chained locator expects second one to be below first in DOM hierarchy. You should be able to find correct button using preceding-sibling xpath. As note selectors like xpath://div[@id=‘main’]/table/tbody/tr[5]/td[5]/form/input[2 and css=.listRowOdd:nth-child(4) > td:nth-child(6) .buttonSmall might not be very stable and should only be used if you are sure that page will not change. You could take parts of the html and ask for help with selectors.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.