V
V
Viktor Familyevich2016-12-08 12:57:40
HTML
Viktor Familyevich, 2016-12-08 12:57:40

How to click on an element in selenium webdriver c#?

The element itself looks like this:

<span class="rating"> 
<span aria-label="Одна звезда" role="button" tabindex="0" class="rating-star" aria-checked="false" aria-pressed="false"></span> 
<span aria-label="Две звезды" role="button" tabindex="0" class="rating-star" aria-checked="false" aria-pressed="false"></span> 
<span aria-label="Три звезды" role="button" tabindex="0" class="rating-star" aria-checked="false" aria-pressed="false"></span> 
<span aria-label="Четыре звезды" role="button" tabindex="0" class="rating-star" aria-checked="false" aria-pressed="false"></span> 
<span aria-label="Пять звезд" role="button" tabindex="0" class="rating-star" aria-checked="false" aria-pressed="false"></span> 
</span>

I want to click on the last element, but I don't understand how. I've tried different things, like this:
IWebElement five_stars = Browser.FindElement(By.CssSelector("span:nth-child(5)"));
            five_stars.Click();

Nothing comes out. Prompt, in Browser.FindElement what to transfer?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Eremin, 2016-12-08
@Wintego

UPD:

Browser.FindElement(By.CssSelector("span.rating > span:last-child")).Click();

Q
qlkvg, 2016-12-08
@qlkvg

In python it works like this:

five_stars = driver.find_element_by_xpath("//span[@aria-label='Пять звезд']")
five_stars.click()

Writing an analogue in C# should not be much work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question