Roro Roro - 9 months ago 46
C# Question

C# Selenium Extract from Div and 2 nested Spans.

I'm trying to get the right syntax with either XPATH or CssSelector using C# to extract the dollar amount shown below:

<div class="a-column a-span3 a-text-right a-span-last a-color-price a-text-bold sc-value">
<span class="a-size-base sc-price-sign">
<span class="a-nowrap">$39.93</span>

Your help would be greatly appreciated. Thank you.


There are many ways to match the element with the desired text in this case. Here is one of the approaches relying on more or less non-layout specific classes that have a relevant meaning:

driver.FindElement(By.CssSelector(".a-color-price > .sc-price-sign > span")).Text;