I am new to Selenium and Python. I would like to navigate through a website, find an element and print it (or store it in a csv file).
Python version: 3.10; Selenium Webdriver: Firefox; IDE: PyCharm 2021.3.2 (CE); OS: Fedora 35 VM
So far I am able to navigate to the appropriate page where a table is generated. When I locate the element by ID and attempt to print it, the output printed is not the element I see on the screen.
My relevant code:
RemainDue = driver.find_element(By.ID, 'b8-b36-Input_RemainAmtYr1')
print ('Remaining Due:', RemainDue)
I expect the output to be something like "100.50", which is what I see on the screen. Instead I get the following:
Remaining Due: <selenium.webdriver.remote.WebElement (session="c33b682a-faa3-4109-8f53-60842fabbbc9", element="32a34d01-66e5-4b98-9577-fab4ca21f988")>
What am I doing wrong?
CodePudding user response:
You are printing the WebElement. Hence you see the output as:
Remaining Due: <selenium.webdriver.remote.WebElement (session="c33b682a-faa3-4109-8f53-60842fabbbc9", element="32a34d01-66e5-4b98-9577-fab4ca21f988")>
You may like to print the text within the element using the text
attribute as follows:
RemainDue = driver.find_element(By.ID, 'b8-b36-Input_RemainAmtYr1')
print ('Remaining Due:', RemainDue.text)