how to validate the options?
Hi, I was trying to validate the options, html is like this.
<div class="panel-sub-heading">
<select class="timeFrame" id="settlementTotals-timeFrame-Widget" ng-model="timeFrame" ng-value="value" ng-options="opt.caption for opt in timeFrameOptions | translate" ng-change="setTimeFrame(timeFrame)"></select>
</div>
There are three options. between select
<option value="0" selected="selected">Yesterday</option>
<option value="1">Last 7 Days</option>
<option value="2">Last 30 Days</option>
My code is:
var option1 = ptor.findElement(protractor.By.css('option [value="0"]')).getText();
expect(option1).toEqual('Yesterday');
I got error as:
Failures:
1) Landing Page - Common Landing Page - widgets: settlementTotals-widget shoul
d show time frame
Message:
NoSuchElementError: Unable to locate element: {"method":"css selector","sel
ector":"option [value=\"0\"]"}
Command duration or timeout: 32 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/
no_such_element.html
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:17:32'
System info: host: 'G3LTD-FCKCZK1', ip: '172.30.237.209', os.name: 'Windows 7',
os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_65'
Session ID: 1678032c-b4d3-4d6a-b6a4-4e675d279143
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, databaseEnabled=true, cssSelectorsEnabled=true, java
scriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox
, webStorageEnabled=true, nativeEvents=false, rotatable=false, locationContextEn
abled=true, applicationCacheEnabled=true, takesScreenshot=true, version=31.0}]
Stacktrace:
NoSuchElementError: Unable to locate element: {"method":"css selector","sel
ector":"option [value=\"0\"]"}
Every time when I try to use ptor.findElement(protractor.By.css, there is an issue like this. Do I miss something? Also, once this By.css doesn't work for me, I tried to add an id and then use By.id which works. Cause I was using By.id a lot, is that the correct way to grab the element form the page?
Many thanks, guys.
Your CSS selector is slightly off - you want by.css('option[value="0"]). Note that there's no space between option and [value. Otherwise, CSS searches for a child element of an option element, instead of the value attribute on the same element.
@juliemr Thank you, Julie.