javascript - Check title of multiple pages in Selenium -
I am currently using WebDriver.js to run some automated tests on the BrowserStack My goal is to take all the href into a given device, open them and see the title of the page where the link is pointing at. To do this I am doing the following:
for (var i = 0; i & lt; hrefs.length; i ++) {var href = hrefs [i], Site_name = sites_names [i]; Driver.get (href); Driver.getTitle () Then (function (title) {assert.equal (title, site_name);}); }
My problem is that both get
and getTitle
are both asynchronous methods and so when I getTitle
The page has already been changed and thus the claim is failing. What is the best pattern / solution for these types of meetings?
If I am reading my question correctly, your claims are failing because of this page Before the completion of the browser is completely full? I think you need a "Waiting" logic in the form of your getTitle
call
var webdriver = require ('selenium-webdriver'); Var Driver = New WebDrive. Builder (). WithCapabilities (webdriver.Capabilities.chrome ()). Build (); Driver.get ('http://www.google.com'); Driver.findElement (webdriver.By.name ('Q')) SendKeys ('webdriver'). . Click on Driver.findElement (webdriver.By.name ('btnG')) (); Driver.wait (function () {return driver.getTitle ()} then (function (title) {return title === 'WebDriver - Google search';});}, 1000); Driver.quit ();
Comments
Post a Comment