I’m starting to lose my mind and was hoping you would help me.
Essentially I’m trying to do a search and if my search term appears in the results then I want to click the hyperlink.
However I can’t use XPath because sometimes the search term appears in Position 1 of 5 in the results and other days it appears in position 3 of 5.
So that’s why I’m trying to do an AssertText and if the text is there, I want to be able to click on it regardless of what position in the results it is.
In my example I’m searching for the term ‘Mattresses’.
So I want to do 2 steps.
Step 1) Firstly, I want to make sure the text “Mattresses” appears in the result (because sometimes it doesn’t and if it doesn’t then I want the test to stop there).
and if it does exist
Step 2) then I want to go ahead and click it…(what ever search ranking position it may be in)
So far I’ve managed to find the xpath for the whole box (highlighted in green)
xpath=//*[@id=“content”]/div/div/div/div/div/div/div
It could be that this text is a generated mess and it is tricky to find the right XPath. Do you have a link to the website so I can play with it?
If I had to automate it, my first try would be to ignore Xpath and use computer vision/OCR instead:
XClickText | matt* ← this command will do what you want
I suggest to use matt* instead of mattresses, because less characters make the word search more robust against OCR recognition mistakes (wrong character etc).
I’m happy to use XClick and OCR if that’s the only way.
I just thought there would be another way without using OCR.
Update: The OCR method works but it always snaps to the test website tab
and I like to run this in the background whilst carrying out other browsing.
Is there a way to stop it from snapping to that window and just running the OCR in the background?