0

I need help with an error when executing a code with selenium in python, where I need to extract some values hosted in a span tag, I have proceeded to save the values in some variables called "cap1, cap2 and cap3". Subsequently I must enter in another field within the web form those values that were saved in the variables mentioned above, when I send the values to that field using send_keys it shows me this data:

 [<selenium.webdriver.remote.webelement.WebElement (session="c89eac54b3083cd46252ddcfaa763150", element="51cb8aa0-f83c-4e9b-8b60-eb660d6ba102")>]

could someone help me with that, it could be that the value I am extracting in the variables is not the correct one, it is worth noting that I used this code:

cap1 = driver.find_element_by_xpath("/html/body/div[5]/div[2]/div/div/form/div[9]/div/div/span[1]")

To extract the value and store it in the variable Should I use another way to extract the value and store it in the variable?

what I really want is to extract a numerical value that is displayed on the web, save it in a variable and then enter it in a field within a form on the same web.

Jose Sosa
  • 1
  • 1

1 Answers1

0

To extract any value from a span tag using Selenium, once you identify the WebElement you need to use the get_attribute() method along with the desired attribute or property as follows:

cap1 = driver.find_element_by_xpath("/html/body/div[5]/div[2]/div/div/form/div[9]/div/div/span[1]").get_attribute("innerHTML")

Incase of extracting the text you can also use the text attribute as follows:

cap1 = driver.find_element_by_xpath("/html/body/div[5]/div[2]/div/div/form/div[9]/div/div/span[1]").text
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352