How can I modify the method to successfully retrieve the text content of an element on a webpage using Selenium with JavaScript? Currently, it is returning undefined.
homepage.js
const { Builder, By, Key, until } = require('selenium-webdriver');
let Basepage = require('../pageobjects/basepage');
class Homepage extends Basepage {
isAviasales(){
driver.findElement(By.xpath("//h1[@class='header__title']")).getText().then(function(txt){
return txt+'';});
}
module.exports = new Homepage();
basepage.js
let webdriver = require('selenium-webdriver');
let driver = new webdriver.Builder().forBrowser('chrome').build();
driver.manage().setTimeouts( { implicit: 10000 } );
class Basepage{
constructor(){
global.driver = driver;
}
go_to_url(theURL){
return driver.get(theURL);
}
}
module.exports = Basepage;
testpage.js
const assert = require('chai').assert;
const homepage = require('../pageobjects/homepage');
let baseurl = 'https://www.aviasales.by/';
describe('Tests are starting', function(){
this.timeout(7000);
it('Mainpage test',function(){
homepage.go_to_url(baseurl);
// assert.equal(homepage.isAviasales(),'Поиск дешёвых авиабилетов');
})
it('Omsk test',function(){
homepage.enterText('Омск');
// assert.equal(homepage.isOMS(),'OMS');
})
it('Swap test',function(){
homepage.clickSwapPlaces();
})
})
MoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetails