Accessing HTML5 Data Attributes using CSS Selector

47 views
Skip to first unread message

Abhishek Verma

unread,
May 22, 2018, 1:33:50 AM5/22/18
to Selenium Users
Hi,

Has any one tried accessing HTML5 Data Attributes using CSS Selector. Below is the HTML snippet.

<span data-test-id="20150119150131011864736" >New claim</span> 

Whenever I'm trying, (span[data-test-id="20150119150131011864736"]) it's not working. 

Error message - Uncaught ReferenceError: Invalid left-hand side in assignment.

Please let me know if any one has encountered the same.

Regards
Abhishek 

meena Sanyasi

unread,
May 22, 2018, 9:38:40 AM5/22/18
to Selenium Users
Use Custom xpath

Abhishek Verma

unread,
May 22, 2018, 9:41:08 AM5/22/18
to seleniu...@googlegroups.com
I tried but it's not working. 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/5acb7ffc-a280-491e-b59a-e312566f44df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David

unread,
May 22, 2018, 3:44:46 PM5/22/18
to Selenium Users
What custom XPath did you try? Worse case, you could always try Javascript access to DOM whether with native javascript or jQuery together with Selenium's JavascriptExecutor to return it back casted as a WebElement.

Abhishek Verma

unread,
May 22, 2018, 9:23:11 PM5/22/18
to seleniu...@googlegroups.com
Hi David,

I tried this -  span[data-test-id="20150119150131011864736"] - <tag[attribute=value]> for CSS but this is not recognizing the element. 

For other solution did you mean, I should try Javascript to get the Xpath of the element. Please help.  

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/a4b554cc-aa9f-425d-bc1e-7fd0d459e528%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Thanks & Regards
Abhishek Verma
Contact - +1 508.762.6133

 


srikanth samala

unread,
May 22, 2018, 10:05:33 PM5/22/18
to seleniu...@googlegroups.com
Have you given Relative xpath :  //span[@data-test-id="20150119150131011864736"]


Your were missing '@' i
Symbol in left hand side. 




--
Thanks & Regards
Abhishek Verma
Contact - +1 508.762.6133

 


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Abhishek Verma

unread,
May 22, 2018, 11:11:44 PM5/22/18
to seleniu...@googlegroups.com
This worked for me in Chrome console to get HTML5 Data Attributes  - $$('[data-test-id="201410081557130002200331"]').



To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.



--
Thanks & Regards
Abhishek Verma
Contact - +1 508.762.6133

 


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CALpnBFTvvLrp%2BYr_6WPOY%2B5yaiyV76S%3DJa9UBtNUYt7b%3DGhdmw%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

David

unread,
May 24, 2018, 8:37:42 PM5/24/18
to Selenium Users
Abhishek, maybe you're confused about XPath? XPath != CSS selector. You provided/tested CSS selector but did not XPath - in one comment/response, you said you tried, but when I asked you responded with a CSS selector.

Try srikanth's XPath suggestion. And make sure you use the right find by method in Selenium for that (XPath vs CSS).


Since you said you got something working in Chrome, try same value with the find by CSS selector in Selenium. That value is different than your original one.



--
Thanks & Regards
Abhishek Verma
Contact - +1 508.762.6133

 


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages