I try to write an automatic test in Selenium with NodeJS and I have a little problem.
First of all, my code:
const {Builder, By, Key, until} = require("selenium-webdriver");
async function example() {
let driver = await new Builder().forBrowser('chrome').build();
await driver.get('http://www.google.com');
await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);
await driver.wait(until.titleIs('webdriver - Google Search'), 1000);
}
example();
Every time i start my app with "node index", a new chrome/firefox app is opening and asking me if I am agree with cookies. I tried to go to settings or to connect my account and allow cookies anytime but if I start again my app, my settings are gone.
I think the solution is to click manually that "I am Agree" button with my code but I don't know how to do this. Can anybody help me, please?
How should I write the code to can click that agree button or what else I should try?
To click on I agree use the following xpath to identify the element
await driver.findElement(By.xpth('//div[text()="I agree"]')).click()
Your code will be
const {Builder, By, Key, until} = require("selenium-webdriver");
async function example() {
let driver = await new Builder().forBrowser('chrome').build();
await driver.get('http://www.google.com');
await driver.findElement(By.xpth('//div[text()="I agree"]')).click();
await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);
await driver.wait(until.titleIs('webdriver - Google Search'), 1000);
}
example();