Running test cases on edge gives "The specified selector is invalid." Same test on chrome runs successfully

306 views
Skip to first unread message

Shikhar Rawat

unread,
Aug 26, 2019, 2:37:06 AM8/26/19
to Selenium Users
Hi All,

I am able to run the test script successfully on chrome browser but same thing when i try to run on Edge browser i get InvaidSelectorException .

Microsoft Edge 44.17763.1.0
Selenium-java 3.141.59
testng-6.14.3

The xpath for which i am getting invalid selector is : Element info: {Using=xpath, value=//a[contains(text(),'Dashboard')]}

What might be possible issue?

Thank-you
edge.PNG
Chrome.PNG

Rohit Ambekar

unread,
Aug 26, 2019, 3:17:36 AM8/26/19
to Selenium Users
Hi Shrikhar, 
conatins(text(),'some text'), sometimes does not work on IE or Edge. Try using css selector or link text or partial link text for identifying your webelement. 

Please let us know changing locator type fixes your issue.

Thanks,
Rohit Ambekar

Shikhar Rawat

unread,
Aug 26, 2019, 4:28:00 AM8/26/19
to Selenium Users
Hi Rohit,

I tried with partial link text it worked !! I haven been wondering for this issue for almost 3 weeks . Thanks a ton!
Can you tell a valid reason as to why .contains() doesnt work in IE or Edge?

There are many elements in my webpage which doesnt have any css selector ,they just have text(not even id or class) how to deal with them then?

Thank-you :D
Shikhar Rawat

Rohit Ambekar

unread,
Aug 26, 2019, 5:09:44 AM8/26/19
to Selenium Users
Hi,

Cool. 
We had same issue while automating our test scripts which were specifically for IE browsers, we were mostly dependent on xpath using contains(text(),'')...
So, somewhere on google I read about the post where it says avoid using contains when you have scripts to be executed on IE browser,  one of the reason is
every browser has different xpath query engine, so sometimes ".contains" may work or may not on IE.  (This is something I understood from that post.)

So, most of the time  try using css-selectors, classname, name etc. Keep xpath as your last option.

If I found that link, I will post that one here.
This link might help you - 

Thanks,
Rohit Ambekar


Reply all
Reply to author
Forward
0 new messages