pythonselenium-webdriver

Cannot find play button on a web page in selenium using python



I am using Python 3.11.9 in windows with google chrome Version 126.0.6478.127 (Official Build) (64-bit).
Here is the simple code
driver = webdriver.Chrome() 
url = "https://onlineradiofm.in/stations/vividh-bharati"
driver.get(url)
radio_is_paused=True
while radio_is_paused:
time.sleep(30)
    play_buttons = driver.find_elements(By.XPATH,'/html/body/div[2]/div/div/div/div[1]/div/div[1]/div/div[2]/div[1]/svg[1]/g/circle')
    if len(play_buttons)>0:
        print(len(play_buttons),' play buttons found')
    else:
        print('play button not found')
driver.quit()

I can see that web page gets opened in a browser and play button is visible .
I am not able to find out the reason that why I get 'play button not found' ?
I have also tried xpath //*[@id="play"]/g/circle , but got same result .
Thanks.


Solution

  • I got it working with https://github.com/seleniumbase/SeleniumBase (pip install seleniumbase). I used ad_block_on=True to block the page ads. Then I had to interact with the site first (clicked "h1"). Finally, I used js_click on "#play circle":

    from seleniumbase import SB
    
    with SB(ad_block_on=True) as sb:
        sb.open("https://onlineradiofm.in/stations/vividh-bharati")
        sb.click("h1")
        sb.js_click("#play circle")
        breakpoint()
    

    Type c and press Enter to leave the breakpoint().