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 = ?????
Use GetAttribute() method:
var element = driver.FindElement(By.TagName("img"));
string imageSrc = element.GetAttribute("src")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With