Skip to content
Advertisement

python selenium cannot locate clickable play button on mobile version of webpage

I am having a hard time locating the play element on a mobile version of a webpage (my python script is passing a mobile user-agent in the header.)

the website url is below (NOTE: must be accessed with a mobile user-agent else it won’t show the correct page and reverts to standard browser page instead)

https://m.soundcloud.com/mbmproductions/sets/mark-berrys-playlist

Using inspect in the browser, I have been unable to work out what exactly is needing to be clicked to start it playing. The entire image area around the play button seems to work if I click on it manually, but no element listed by inspect seems to work when using the script to start it playing.

Can anyone explain how to find the correct clickable element in this link so I can add it to a script in order to click it and start it playing. Ideally using XPATH as per my code below, but class or ID or anything would do if it works, even javascript if I have to.

    element = WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((By.XPATH, targetelement))
    )
    element.click()

Advertisement

Answer

I make some amendment to your script. Use action instead of click(). Change clickable explicit to presence.

element = WebDriverWait(driver, 10).until(
        EC. presence_of_element_located
((By.CLASS_NAME, ‘g-header-artwork-controls’))
    )

el = driver.find_elements_by_css_selector(“.playlist__playButton.g-play-button")
webdriver.ActionChains(driver).move_to_element(el).click(el).perform()
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement