Reputation: 55
<div class="video-options">
<ul class="video-options-text">
<li id="like">
<a href="#" title="LIKE Video" target="_blank">5 LIKES</a>
</li>
<li>
<a href="https://static-video.varzesh3.com/local/99-02-24/Sadat.mp4">Download <span class="demo-icon icon-download"></span></a>
</li>
<li class="share-button">
<span class="share">Share</span>
<div class="hover" style="width: 115px;">
<span class="tooltip-text">
<a
I have these codes and I want to use selenium and click on like button. I'v tried already with Xpath , Css_element , Id , ActionChains , etc.
None of them haven't work!
This is link : Video
Update Photos
This is "Like" button that i need to click it with selenuim.
The Whole The Codes
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
address = "https://video.varzesh3.com/"
driver = webdriver.Chrome(executable_path='C:/Program Files/Python37/Scripts/chromedriver.exe')
driver.get(address)
time.sleep(2)
driver.find_elements_by_tag_name("span")[2].click()
time.sleep(2)
driver.find_elements_by_class_name("left-dir")[0].send_keys("Email")
time.sleep(2)
driver.find_elements_by_class_name("left-dir")[1].send_keys("Password")
time.sleep(2)
driver.find_elements_by_class_name("register")[3].click()
time.sleep(2)
driver.find_elements_by_class_name("title")[0].click()
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"li#like>a"))).click()
Upvotes: 1
Views: 64
Reputation: 33384
To click on Like
induce WebDriverWait
() and wait for element_to_be_clickable
() and following css selector.
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"li#like>a"))).click()
Import below libraries.
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
Updated code: Need to switch new window first.
driver.switch_to.window(driver.window_handles[-1])
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"li#like>a"))).click()
Upvotes: 1