Reputation: 87
Can we use browser.findElement()
method for non Angular application instead of using browser.driver.findElement()
method?
Upvotes: 2
Views: 5355
Reputation: 2098
I guess your question is for browser.driver.findElement
vs browser.element
browser.driver.findElement
method returns webElement
which is the provided by webDriver
(Selenium).
When you call browser.driver.findElement(locator)
, WebDriver immediately sends a command over to the browser asking it to locate the element. These WebElement
provides actions methods which can be used to interact with browser.
browser.element
method returns ElementFinder
object which is provided by protractor
.
Unlike WebElement
when you call browser.element(locator)
, ElementFinders
just store the locator information but won't ask browser to find element until an action method is called.
This is great for creating page objects, because we'll be able to reuse things which defined in setup (before a page may have been loaded).
All WebElement
actions are wrapped and available on the ElementFinder
, in addition to a couple other helper methods provided by protractor.
Also you can always access the underlying WebElement
using element(locator).getWebElement()
, but you should not need to as you can use browser.element(locator)
method for non Angular application also.
Upvotes: 3
Reputation: 373
You only need to access the webdriver instance by using browser.driver:
browser.driver.findElement(by.css('[data-ptor="submit-btn"]'));
It can be even more elegant, in your config.js:
onPrepare: function() {
global.dvr = browser.driver;
}
In your test:
dvr.findElement(by.css('[data-ptor="submit-btn"]'));
Protractor waits for Angular to finish its work, though you can tell it not to be that smart about your non-Angular app:
beforeEach(function() {
return browser.ignoreSynchronization = true;
});
Upvotes: 1