Zanam
Zanam

Reputation: 4807

Python selenium unable to copy text via full xml path

I have already been through various threads here on SO but it hasn't worked for me so far.

I am using the following code:

from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
xPathFull = r'/html/body/div[2]/div[2]/div[1]/div[1]/div/form/div[2]/div[2]/input'
path_to_chromedriver = r'C:\chromedriver'  # change path as needed
browser = webdriver.Chrome(executable_path=path_to_chromedriver)
.........
.........
content = browser.find_element_by_xpath(xPathFull).text

The html of the location I am trying copy text from is:

<input name="shortLink" type="text" value="https://shrsl.com/2dsda" onfocus="this.select();" readonly="">

Basically I want the content variable above to store the value https://shrsl.com/2dsda

Upvotes: 1

Views: 201

Answers (1)

MR Mark II
MR Mark II

Reputation: 453

Try:

content = browser.find_element_by_xpath(xPathFull).get_attribute('value')

Upvotes: 3

Related Questions