Trying to write a text in a spreadsheet like screen having dynamic ID's only

I have a screen which contains a spreadsheet like feature. I want to write a certain text into some of the cells.

Unfortunately, I can not use existing XPath / Attributes.
image
Xpath:Attributes and Xpath:idrelative can not be used as the ID’s are refreshing after each release.
Position cannot be used as it highlights 5 cells and is choosing any of these cells but not the correct one.


Same happens with attributes.

image
This screenshot shows the Inspection tool.

I also thought about using Send Keys plus Tab, but without having an object saved, I cannot use Tab.

Does anyone have any idea how I can enter text into different cells? Much appreciated.

Keep the tag, delete the id and class and try the below xpath. Hopefully, it will find something unique :neutral_face:.

//div[@class="ss-sm"]/div[1] and div[@class="ss-sm-ltdot"]/preceding-sibling::div[1]

Edit:
or maybe

//div[@class="ss-sm-inner" and parent::div[@class="ss-sm"] and following-sibling::div[@class="ss-sm-ltdot"]]

Hi,

Thank you for the input.

Unfortunately I get the following two error messages, dependent I click the element or set text.
Any idea, what it means and how to fix it?
Set text.txt (5.6 KB)
Click element.txt (5.9 KB)

These are your errors.

Caused by: org.openqa.selenium.InvalidElementStateException: invalid element state

and

Caused by: org.openqa.selenium.ElementNotInteractableException: element not interactable

It seems your element is not able to take input or be clicked at the time you do it, like the element is in a read-only state. When you enter text manually, do you need to do anything beforehand? Did you get the correct element to highlight when you tested the pathway? One of the <div> tags in your picture is hidden, so you do not want that one.

To verify your pathway by highlighting it, in your HTML window, click on it and hit CTRL + F. Then, copy and paste the pathway into the Find/Search textbox.

Edit: to the right of the Find/Search textbox, after you enter the pathway, you should see “1 of 1” (hopefully). If you see anything else, then we may not have an unique pathway. If you see nothing to the right, then we don’t have a valid pathway.

1 Like

Hi grylion54,

I experimented a bit and found this attribute //*[@data-cid = ‘1$7’] . Now I am able to move to and click each cell. Unfortunately I cannot write any text in it as I get the following error message:
error message.txt (5.7 KB)

The cell is div, I tried to find other properties, but couldn’t find any. Maybe you have an idea?

Again, you are getting a similar error that you had with the previous time that you tried to enter text into a cell.

Caused by: org.openqa.selenium.ElementNotInteractableException: element not interactable

How do you enter text into the spreadsheet when you do it manually? Do you have to click on a cell and then type some text? However you do it manually, that is how you have to do it via your script. In some instances, like if this is a SalesForce application, a page will only respond after you do something, such as click on a cell. The ability to “setText” does not exist until then.

WebUI.click(...)
WebUI.waitForElementClickable(...)
WebUI.delay(1)  // don't know how long to wait
WebUI.setText(...)

Edit: In a SalesForce sample site, I even tried to write a pathway to an element and couldn’t get it to work. I had to use the Web Spy to get a pathway, and it was a very fragile looking pathway at that. When I tried to click to look at the HTML, the pathway did not exist until after I had clicked on the element.

1 Like

Hi grylion54,

thank you for your input. I added the lines of code you provided (WaitForElementClickable etc.), but same result.

It is very interesting though: After this result I was using the webspy and got a weird result

The scenario is to click on a cell and enter values. Some cells are simple text fields, other cells are dropdowns with a typeahead as you can see here

But the webspy didn’t record any of the data entered (only for the dropdown it recognized an input and the entered text. For all other fields it only recognized the click, but not for 4 different fields - only for the same field entered.
image

Do you have an idea, what could cause this?

First, you import all necessary packages related to xls/xlsx and then then write code for how to set values into each column and rows using setValueToCellByIndex(dataSheet, rowIndex, 24)