I am trying to set up following actions with Selenium-Webdriver and NodeJs:
- Open Firefox
- Go to Google.com
- Search a name in Google
- Wait for the page to load
- Select and click the next to the second page.
I am stuck on the last step and have searched similar questions on StackOverflow, but none of the answers have allowed me to locate the or tags for "next" or "page 2". I even copied the completed XPath through inspection, but always received "NoSuchElementError".
Thank you for your help.
const { Builder, By, Key, until, Wait } = require('selenium-webdriver');
require('geckodriver');
const faker = require('faker');
const searchGoogle = async () => {
let name = faker.name.findName();
let driver = await new Builder().forBrowser('firefox').build();
try {
await driver
.manage()
.window()
.maximize();
await driver.manage().deleteAllCookies();
await driver.get('http://google.com');
await driver.findElement(By.name('q')).sendKeys(name, Key.RETURN);
await driver.wait(until.titleIs(name), 1000);
await driver
.findElement(By.xpath("//span[contains(text(), 'Next')]"))
.click();
} catch (err) {
console.error(err);
} finally {
driver.quit();
console.log('complete!');
}
};
searchGoogle();