Home > Back-end >  How to get text of element without it being visible in Selenium
How to get text of element without it being visible in Selenium

Time:08-03

I have a problem getting text from a table that can be shown by a button click, the data for that table are present even before the button be clicked, but when I try to get it, it returns nothing, if I try to push the button first, it successfully gets the text, is there a solution for this ? By the way, I am using Xpath to get the element.

table = f'(//div[child::table[child::tbody[child::tr[child::td[text()="Student Name:"]]]]])[{self.row}]'
self.studentName = self.dataBrowser.find_element(By.XPATH, table '/table[1]/tbody/tr[1]/td[2]').text

CodePudding user response:

Probably you are missing a delay here.
I mean probably you are extracting the text from web element before it is fully loaded, containing it text content.
In several cases waiting for the visibility of the element you are extracting the text from will resolve your problem.
To give more precise answer we need to see all your code, including the page you are working on to make some debugging and testing.

  • Related