Reinaldo Villasmil
Reinaldo Villasmil

Reputation: 7

Click span element using selenium

I would like to know how can I click on this element using selenium:

<span data-val="BB9049_600"> 7.5 </span>

Since there is no class or id with the span element I cant approach it that way. The xpath is:

//*[@id="buy-block"]/div[1]/div[5]/div[3]/form/div[2]/div[2]/div/div/div/div[2]/div/ul/li[2]/span

Upvotes: 0

Views: 2937

Answers (2)

mahesh
mahesh

Reputation: 109

you can use css selector as below

driver.findelement(By.CssSelector("[data-val='BB9049_600']"))

also by looking at 'data-val' value it seems 600 in 'BB9049_600' is not a constant value if that is the case then you can use below to check if selector starts with value

driver.findelement(By.CssSelector("[data-val^='BB9049_']"))

Upvotes: 0

Andersson
Andersson

Reputation: 52685

You can try to use text content of required element as

//span[normalize-space()="7.5"]

or value of data-val attribute:

//span[@data-val="BB9049_600"]

Upvotes: 3

Related Questions