I want to extract data from a meta tag but the tag is as follows
<meta property="og:description" content="blah"/>
Since there is no id/class/etc. I can't use
driver.FindElement(By.[id/class/etc.]);
This meta tag has a unique property and content so I am wondering if there is any better way to locate and extract the content than selecting all "meta" tags and iterating through them.
While extracting data from a meta tag, I would suggest to use the attributes as much as possible. In your case :
XPath:
driver.FindElement(By.XPath("//meta[@property='og:description' and @content='blah']"));
CssSelector:
driver.FindElement(By.CssSelector("meta[property='og:description'][content='blah']"));
You can use xPath to grab the specified meta tag
driver.FindElement(By.XPath("//meta[@property='og:description']"));
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