XPath is not working even when directly copied from Chrome inspect

Issue

I have been trying to automate my work and we use service-now for our requests. However, for the the life of me I can not get Selenium to run properly on the service-now website. It works on the login page before entering, but no matter what form of locater or x path I use it will not work. The website is dynamic so I am pretty sure xpath is needed.

I have tried directly from Google Chrome inspect as well as other xpath possibilities:

//*[@id="row_sc_request.sc_task.request_65091fb5db8163c4bc8f18df4b961921"]/td[3]/a

xpath=//a[starts-with(text(),'Open record: SCTA')]

xpath=//a[class="linked formlink" and starts-with(@aria-label='Open record: SCTA')]

This is the element copied from chrome

<a class="linked formlink" aria-label="Open record: SCTASK0067185" href="sc\\\_task.do?sys\\\_id=65091fb5db8163c4bc8f18df4b961921\\\&amp;sysparm\\\_record\\\_target=sc\\\_task\\\&amp;sysparm\\\_record\\\_row=1\\\&amp;sysparm\\\_record\\\_rows=1\\\&amp;sysparm\\\_record\\\_list=request%3D9509dbb5db8163c4bc8f18df4b96199f%5EORDERBYDESCnumber">SCTASK0067185</a>

Can someone please review my code? Any help would be appreciated!

Solution

Thank you for all your answers. It turns out all I needed to do was switch the IFrame.
I am fairly new to this so I had no idea.

In my situatuion, I had to write:

"browser.switch_to.frame(browser.find_element_by_name('gsft_main'))"

where gsft_main is the name of the frame.

After doing this, then I was able to use:

browser.find_element_by_xpath("//a[@class='linked formlink' and starts-with(@aria-label, 'Open record: SCTA' )]")

and it worked out.

Answered By – Nicholas Deering

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published