My current automation test involves logging into a hotel booking website using Selenium and Cucumber. After successfully logging in, I attempt to click on a checkbox labeled "wifi", but encounter issues with Selenium not functioning properly once logged in.
I am able to enter the username and password on the login page without any problems, but for some reason Selenium stops working after the login process, preventing me from clicking on the wifi button. I have tried using implicit wait, but this does not resolve the issue.
Below is the code snippet:
const {By, Key, Builder} = require("selenium-webdriver");
require("chromedriver");
const {Before, Given, When, And, Then} = require('@cucumber/cucumber')
let driver = new Builder().forBrowser("chrome").build();
var {setDefaultTimeout} = require('@cucumber/cucumber');
setDefaultTimeout(60 * 1000);
Given('when you are on the login page', async function () {
await driver.get("https://automationintesting.online/#/admin")
});
When('you enter login credentials', function () {
driver.findElement(By.id("username")).sendKeys("admin");
driver.findElement(By.id("password")).sendKeys("password");
driver.findElement(By.id("doLogin")).click();
});
When('you are logged in', async () => {
await driver.manage().setTimeouts({ implicit: 3000 });
await driver.findElement(By.id("wifiCheckbox")).click();
});
Then('you should be on the profile page', function () {
driver.getCurrentUrl();
});
The section of code that functions correctly is as follows:
driver.findElement(By.id("username")).sendKeys("admin");
driver.findElement(By.id("password")).sendKeys("password");
driver.findElement(By.id("doLogin")).click();
However, the portion of code below is where the issue arises:
driver.manage().setTimeouts({ implicit: 3000 });
await driver.findElement(By.id("wifiCheckbox")).click();
I AM ENCOUNTERING A REQUEST FAILED 403 ERROR MESSAGE