How to get img src in string in selenium using python How to get img src in string in selenium using python selenium selenium

How to get img src in string in selenium using python


what you are interested is not a text, it's an attribute with name src. so if you will do something like that, you won't get what you want.

find_element_by_id("idFOO").text

if your html is like this,

<input id="demo">hello world </input>

then the following code will give you hello world

driver.find_element_by_id("demo").text

and following code will give you demo

driver.find_element_by_id("demo").get_attribute("id")

so in your case, it should be

driver.find_element_by_id("idFOO").get_attribute("src")


Try:

src = driver.find_element_by_xpath("//div[@class='rc]/h3[@class='r']/a/img").get_attribute("src")

P.S.- Used full available xpath to avoid duplicate conflicts on actual DOM.