Home > database >  Select rating using selenium web driver
Select rating using selenium web driver

Time:01-29

I am trying to select the 5 star user rating on this Website:

I have tried using actions but I've been unsuccessful.

element = driver.find_element(By.XPATH, '/html/body/div[1]/div/div/div[3]/div/div/article/div[3]/div[3]/div/div[5]/div[1]/span/span')
action = ActionChains(driver)
action.move_to_element(element).perform()
action.move_to_element(driver.find_element(By.XPATH, "//span[@data-user-rate='100']")).click()

CodePudding user response:

You can get the width of the //span[@class='user-rate-image post-large-rate stars-large'] Then you will need to click the x coordinate using the width

In this case the width is 87, so you would click pixel 87

You can do this by using the move_to_element_with_offset method in the ActionChains class.

CodePudding user response:

It's hard to hover element to make the rating 100% with ActionChains (it's always about 100, but not 100).

Try with js, works for me.

rating = driver.find_element(By.XPATH, "/html/body/div[1]/div/div/div[3]/div/div/article/div[3]/div[3]/div/div[5]/div[1]/span/span")
driver.execute_script('arguments[0].style="width:100%"; arguments[0].click()', rating)
  •  Tags:  
  • Related