M
M
Mykyta_M2018-01-05 15:36:04
Python
Mykyta_M, 2018-01-05 15:36:04

How to drag volume slider using Selenium + Python?

Hello! Can you please tell me how to drag the volume slider on this site using Selenium + Python ?
Is there a solution using Javascript?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Sovetnikov, 2018-01-05
@Mykyta_M

import time
from selenium import webdriver
from selenium.webdriver import ActionChains

driver = webdriver.Chrome()
driver.get('https://salsabeatmachine.org/')

move = ActionChains(driver)
# Ползунок BPM
thumb = driver.find_element_by_class_name('mat-slider-thumb')

# Открываем ползунок громкости пиано
driver.find_element_by_xpath('/html/body/bm-root/div[2]/mat-card[2]/div[4]/bm-instrument-tile/div/div[2]/button[2]/span/mat-icon').click()
# Сам ползунок громкости
piano_thumb = driver.find_element_by_xpath('/html/body/bm-root/div[2]/mat-card[2]/div[4]/bm-instrument-tile/mat-slider/div/div[3]/div[2]')

# Пускаем музыку
driver.find_element_by_class_name('mat-button').click()
time.sleep(2)
# Выключаем пианино и делаем такт быстрее
move.click_and_hold(thumb).move_by_offset(10, 0).release().perform()
move.click_and_hold(piano_thumb).move_by_offset(-200, 0).release().perform()
time.sleep(4)
# Ещё чуть быстрее
move.click_and_hold(thumb).move_by_offset(20, 0).release().perform()
time.sleep(4)
driver.quit()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question