Code :
var assert = require('assert');
describe('webdriver.io api page', function() {
it('should open login page', function () {
browser.url('/login');
browser.pause(10000);
})
it('Should enter login details and submit', function() {
browser.pause(10000);
browser.element(By.xpath("//input[@type='text' and @aria-label='user name']")).sendKeys("mikestr");
})
});
I am new to webdriverIO and trying to locate username textbox using xpath but it throws me error. I look around many webdriverIO material but did not get solution for this yet.
WebdriverIO's Selectors are different than Selenium Webdriver. It will accept the String value for either "XPath" or "CSS" selectors. The "By is not defined" Error you're seeing is because it's looking for a "String" value of a selector.
Documentation: http://webdriver.io/guide/usage/selectors.html#CSS-Query-Selector
In your situation you would only need to pass something like:
browser.element('"//input[@type='text' and @aria-label='user name']"')
.setValue('mikestr')
Alternatively you could set the variable and pass a variable like:
var XPath = "//input[@type='text' and @aria-label='user name']"
browser.element(XPath).setValue('mikestr')