TesterHQ - The Evil Tester Blog Aggregator

Aug 25, 2016 - 1 minute read - FAQ Selenium Simplified Selenium Simplified Blog

How to Select a Web Element with an id containing '.'

Original Blog Posting on [SeleniumSimplified.com]

TLDR: \.

Lesson learned.

I was working with a site and trying to select an element via its id e.g.

<p id="select.me.by.id">Select Me By My id</p>

Simples thought me:

  • #select.me.by.id


So I did what all good Selenium debuggers do… I tried in the browser but Chrome didn’t match it.

Tempted though I was to blame Chrome, I tried with XPath, and that worked fine:

  • //p[@id='select.me.by.id']

After a bit of web searching, the solution was clear.

In CSS I wasn’t saying, find the id select.me.by.id

I was saying find the id select with class me by id which was not at all what I wanted.

Fortunately CSS offers escaping, which I didn’t realise.

Until the app is fixed I can locate the id using CSS with:

  • #select\.me\.by\.id