Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
Return text of element on the page

How do I make the method return the text value of an element on the page, using Selenium with JS? Now returns 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();
    })
})

MoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetailsMoredetails

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Looks like you are missing a wait here.
I guess the element you are trying to access is still not completely loaded on the web page when you trying to access it and retrieve it's text content.
To give better answer we need to see all your code here.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!