0

I am using selenium and python to learn about automation web testing.

I want to click on the fivest or excelent button, while there is only span in it (I had learned that using id instead of span is so much easier) but in this case, I want to click the span.

I am using below code:

driver.find_element(By.XPATH, '//span[@class="ui_bubble_rating fl bubble_50"]').click()
    driver.find_element(By.XPATH, '//span[@data-value="5"]').click()

there is five choice, very bad, bad, ok, good, excellent and i want to choose the excelent one, the picture of the five/excelent :

the button i want to click

here is the element :

the element

the class and the data-value change and depend of what we choose if is it excelent the class will be "ui_bubble_rating fl bubble_50" and the data-value will be "5" but if it is very bad it will be "ui_bubble_rating fl bubble_10" and the data-value will be "1"

Thank you for everyone who help me.

1
  • can you share the url or post the html before select the ratings? it will be very hard to provide solution without url or relevant html. Commented Sep 26, 2022 at 19:18

1 Answer 1

1

This might help (from a Tripadvisor rating system):

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains


chrome_options = webdriver.ChromeOptions()
browser = webdriver.Chrome(options=chrome_options)
browser.get('https://www.tripadvisor.in/UserReviewEdit-g641714-d1156207-Club_Mahindra_Madikeri_Coorg-Madikeri_Kodagu_Coorg_Karnataka.html')
elem = browser.find_element(By.XPATH, '//span[@id="bubble_rating"]')

action = ActionChains(browser)
action.move_to_element_with_offset(elem, 50, 0).click().perform()

In that site, the class bubble_50 is added on mouse hover. However, I just offset the clicking. There might be other solutions out there. You can validate by checking the class and value (after the click)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.