Open ShaharGilad opened 3 years ago
Running the Following code 3 times, 1 time passed, and 2 cause a StaleElementReferenceError error.
const { By, Key } = require('selenium-webdriver'); const { Builder } = require('@tpio/javascript-opensdk'); const { assert } = require('chai'); const CONSTANT = { TOKEN: 'TOKEN', DATES:{ IN:'2021-05-01', OUT:'2021-05-08' } }; describe("Edge airbnb test",() =>{ let driver; beforeEach(async ()=>{ driver = await new Builder().forBrowser('MicrosoftEdge').withToken(CONSTANT.TOKEN).build(); }); afterEach(async()=>{ await driver.quit(); }); it("Book a room", async () =>{ await driver.get('https://www.airbnb.com/'); const input = await driver.findElement(By.xpath("//input[contains(@id, 'bigsearch-query-detached-query-input')]")); await input.click(); await input.sendKeys('NYC'); await driver.findElement(By.css('[data-testid="structured-search-input-field-split-dates-0"]')).click(); await driver.findElement(By.css(`[data-testid="datepicker-day-${CONSTANT.DATES.IN}"]`)).click(); await driver.findElement(By.css(`[data-testid="datepicker-day-${CONSTANT.DATES.OUT}"]`)).click(); await driver.findElement(By.css('[data-testid="structured-search-input-field-guests-button"]')).click(); await driver.findElement(By.css('[data-testid="stepper-adults-increase-button"]')).click(); await driver.findElement(By.css('[data-testid="stepper-adults-increase-button"]')).click(); await driver.findElement(By.css('[data-testid="stepper-children-increase-button"]')).click(); await driver.findElement(By.css('[data-testid="stepper-children-increase-button"]')).click(); await driver.findElement(By.css('[data-testid="stepper-children-increase-button"]')).click(); await driver.findElement(By.css('[data-testid="structured-search-input-search-button"]')).click(); const ele = await driver.findElement(By.css('h1[tabindex="-1"]')); const title = await ele.getText(); assert.equal(title,'Stays in New York'); const typeOfPlace = await driver.findElement(By.xpath("//div[contains(@id, 'menuItemButton-room_type')]")); await typeOfPlace.click(); await driver.findElement(By.xpath("//input[contains(@id, 'filterItem-room_type-checkbox-room_types-Entire_home_apt')]")).click(); await driver.findElement(By.xpath("//input[contains(@id, 'filterItem-room_type-checkbox-room_types-Private_room')]")).click(); await driver.findElement(By.xpath("//input[contains(@id, 'filterItem-room_type-checkbox-room_types-Hotel_room')]")).click(); await driver.findElement(By.xpath("//button[contains(@id, 'filter-panel-save-button')]")).click(); await driver.findElement(By.xpath("//div[contains(@id, 'menuItemButton-price_range')]//button")).sendKeys(Key.ENTER); const minPrice = await driver.findElement(By.xpath("//input[contains(@id, 'price_filter_min')]")); await minPrice.sendKeys(Key.chord(Key.CONTROL,"a",Key.DELETE)); await minPrice.sendKeys('500'); const maxPrice = await driver.findElement(By.xpath("//input[contains(@id, 'price_filter_max')]")); await maxPrice.sendKeys(Key.chord(Key.CONTROL,"a",Key.DELETE)); await maxPrice.sendKeys('2000'); await driver.findElement(By.xpath("//button[contains(@id, 'filter-panel-save-button')]")).click(); const roomElement = await driver.findElement(By.xpath('//*[@id="ExploreLayoutController"]/div[1]/div[1]/div[2]/div/div[2]/div/div/div[3]/div/div/div/div/div[1]/div/div/div/div/div[2]/a')); const url = await roomElement.getAttribute('href'); await driver.get(url) const roomTitle = await driver.findElement(By.css('[data-plugin-in-point-id="OVERVIEW_DEFAULT"]')); const displayed = await roomTitle.isDisplayed(); assert.equal(displayed, true); driver.report().step('Room screenshot', 'Airbnb room screenshot', true); }); });
The error message:
Doesn't happen on Chrome/Firefox?
Firefox works fine. I ran the code with chrome and the same error StaleElementReferenceError: happened 3 of 5 times.
StaleElementReferenceError:
Running the Following code 3 times, 1 time passed, and 2 cause a StaleElementReferenceError error.
The error message: