0

Currently a beginner, I am trying to click a video so it would start playing:

<div class="jw-media jw-reset"><video class="jw-video jw-reset" tabindex="-1" disableremoteplayback="" webkit-playsinline="" playsinline="" x-webkit-airplay="deny" preload="metadata" src="/get_file/1/d9ce3f3e42f691a717900763bb60674bd97739d341/64000/64857/64857_hq.mp4/?d=3166&amp;br=626&amp;ti=1645665256" __idm_id__="147457" style="object-fit: fill;"></video></div>

I tried to use:

element = browser.find_element(By.CSS_SELECTOR, ".jw-media")
element.click()

as a css selector from right clicking the div from inspect elements and copying the css selector. I've also tried

element = browser.find_element(By.CLASS_NAME, "jw-video jw-reset")

but that doesn't work either, what am I doing wrong?

petezurich
  • 9,280
  • 9
  • 43
  • 57
test test
  • 1
  • 3
  • There should be an element with a label similar to play-button. have you found that? You might get better help if you provide more data (the site you are connecting to, or your code). – Shawn Ramirez Feb 24 '22 at 20:44

2 Answers2

0

The desired element is a dynamic element, to click() on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.jw-media.jw-reset > video.jw-video.jw-reset[src]"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='jw-media jw-reset']/video[@class='jw-video jw-reset' and @src]"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

So I found out that the answer to the question was because the site I was trying to access had an ad on top of the video player which opened a new tab once it clicked on the video but I couldn't tell because I use an adblocker. I installed an adblocker by downloading the .xpi file and installing it with selenium.

browser.install_addon(filelocation, temporary=True)

Thanks for the replies and help everyone.

test test
  • 1
  • 3