Question

I have a problem while escaping the special character -. Here is the HTML code snippet:

<input class="form-control dob ng-pristine ng-valid" type="text" readonly="readonly" data-date-format="mm/dd/yy" ng-model="pollObj.poll_question.start_time" datepicker=""></input>

<span></span>

<input class="form-control dob ng-pristine ng-valid" type="text" readonly="readonly" data-date-format="mm/dd/yy" ng-model="pollObj.poll_question.end_time" datepicker=""></input>

I am using watir web driver to select a date from the date picker.

So if I have to click the first input from the above html snippet, the only thing that can be distinguished is the value for ng-model. Hence I thought of writing like this:

browser.input(:ng-model="pollObj.poll_question.start_time").when_present.click

In the above code, I need to escape - in ng-model. Using backslash doesnot help.

Can someone please help?

Was it helpful?

Solution

The ng-model is not a standard attribute, so Watir-Webdriver does not directly support the attribute as a locator.

One option is to use a css-selector:

browser.element(:css=> 'input[ng-model="pollObj.poll_question.start_time"]').when_present.click

Or you could use xpath:

browser.input(:xpath => './/input[@ng-model="pollObj.poll_question.start_time"]').when_present.click
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top