Roro Roro - 1 year ago 90
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.

Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download