Reputation: 153
I'm new to Selenium and i'm trying to get the "src" value from a IWebElement
and convert it to a string (C#). I am able to get a simple text value from elements using their built in .Text
, but that will only give me the inner html. Here's the sample code:
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://somewebsite");
var val = driver.FindElement(By.TagName("img"));
string imageSrc = ?????
Upvotes: 3
Views: 8644
Reputation: 1
use xPath, for example
//img[@src='The image src']
Also you can use assert.istru
and .Displayed
Upvotes: 0
Reputation: 473833
Use GetAttribute()
method:
var element = driver.FindElement(By.TagName("img"));
string imageSrc = element.GetAttribute("src")
Upvotes: 8