-1

I want to be able to select text on a website, store it, and then turn that stored information into a variable. More specifically as seen in the picutre below, my goal is for the selected name, in this case, John J. John, somehow be copied, turned into a variable, and then printed, all without emulating any key binds.

HTML Inspect element photo

The code I have tried to use to get the information is this:

selectedName = browser.find_element_by_xpath('//*[@id="sign_in_box"]/div/div[2]/div/div[1]/div').get_attribute("div")

print (selectedName)

The return I am getting is this:

None

I know that the problem almost definetly lies somewhere in the path, but I can't figure it out.

lst00
  • 1
  • 1
  • There is no element with the ID `#sign_in_box` in the HTML output. Please make sure, that you provide a full but minimal example to your problem, so that others have a chance to spot errors or mistakes. – feeela Feb 10 '21 at 01:26

1 Answers1

0

Assuming your xpath is correct, you should put .text instead of .get_attribute("div") since it will not return the text you want, but the div itself.

How to get text with Selenium WebDriver in Python

Try

selectedName = browser.find_element_by_xpath('//*[@id="sign_in_box"]/div/div[2]/div/div[1]/div').text
Jimmy Suh
  • 202
  • 2
  • 13