[Python] Python | Selenium | Adjusting the value on a price slider with min/max values

Discussão em 'Python' iniciado por Stack, Fevereiro 17, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working on a practice Selenium script to adjust the value of a price slider that has min and max value sliders on the same bar. The code technically works, and I see the max slider value adjust, but not to the exact value I want. Is there a better way I can be doing this?

    The code I'm working with at the moment is:

    def test_priceScale():
    driver.get('https://www.practicesoftwaretesting.com')

    slider = driver.find_element(By.CSS_SELECTOR, "span[aria-label = 'ngx-slider-max']")

    current_value = float(slider.get_attribute('aria-valuenow'))
    max_value = float(slider.get_attribute('aria-valuemax'))

    target_value = 10

    slider_width = slider.size["width"]
    offset = (target_value - current_value) / (max_value * slider_width)

    actions = ActionChains(driver)
    actions.click_and_hold(slider).move_by_offset(offset, 0).release().perform()


    My hope is to find a solution that if I change the value of target_value, I can see the slider adjust to that specific price.

    Continue reading...

Compartilhe esta Página