Open ShaharGilad opened 3 years ago
Running the following code with Chrome headless/standard, Edge and Firefox drivers. Failed with StaleElementReferenceError error with Chrome and Edge, on the other hand, it works with Firefox driver.
const { By, Key } = require('selenium-webdriver'); const { Builder } = require('@tpio/javascript-opensdk'); const { assert } = require('chai'); const CONSTANT = { TOKEN: 'TOKEN', DATES:{ IN:"2021-05-12", OUT:"2021-05-16" } }; describe('Chrome booking test', () => { let driver; before(async ()=>{ driver = await new Builder().forBrowser('chrome').withToken(CONSTANT.TOKEN).build(); }); after(async()=>{ await driver.quit(); }); it.only('Search hotels in NYC', async () => { await driver.get('https://www.booking.com/'); const locationInput = await driver.findElement(By.id('ss')); await locationInput.sendKeys('NYC'); await driver.findElement(By.xpath("//div[contains(@class, 'xp__dates xp__group')]")).click(); await driver.findElement(By.css(`[data-date='${CONSTANT.DATES.IN}']`)).click(); await driver.findElement(By.css(`[data-date='${CONSTANT.DATES.OUT}']`)).click(); await driver.findElement(By.id('xp__guests__toggle')).click(); const addChildrenButton = await driver.findElement(By.css("[aria-label='Increase number of Children']")); await addChildrenButton.click(); await addChildrenButton.click(); await addChildrenButton.click(); await driver.findElement(By.css("[data-group-child-age='0']")).sendKeys(Key.ENTER,Key.DOWN,Key.DOWN,Key.ENTER); await driver.findElement(By.css("[data-group-child-age='1']")).sendKeys(Key.ENTER,Key.UP,Key.UP,Key.ENTER); await driver.findElement(By.xpath("//button[contains(@class, 'sb-searchbox__button')]")).click(); const mainTitle = await driver.findElement(By.css('.sr_header')).getText(); assert.include(mainTitle,'New York'); await driver.findElement(By.xpath("//a[contains(@data-id, 'class-5')]")).click(); await driver.findElement(By.xpath("//a[contains(@data-id, 'class-4')]")).click(); await driver.findElement(By.xpath("//a[contains(@data-id, 'review_score-80')]")).click(); await driver.findElement(By.css(".sr_item_photo_link")).click(); }); });
The error:
Running the following code with Chrome headless/standard, Edge and Firefox drivers. Failed with StaleElementReferenceError error with Chrome and Edge, on the other hand, it works with Firefox driver.
The error: