Choosing the video quality by using selenium in Trovo - python

I'm having a problem selecting a quality resolution from a video on Trovo
Please help me switch to 480P. Can't find the info. Thanks
from selenium.common import NoSuchElementException
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
options = webdriver.ChromeOptions()
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_argument("--mute-audio")
driver = webdriver.Chrome(executable_path='chromedriver', options=options)
driver.maximize_window()
driver.implicitly_wait(20)
driver.get("https://trovo.live/")
time.sleep(5)
driver.find_element(By.XPATH,
"""/html/body/div[1]/div/div/div[1]/div[2]/section[1]/div/section/div[1]/div/div/div[1]/div/div[1]/div/div[2]/div[2]""").click()
time.sleep(5)
def check_exists_by_xpath(xpath):
try:
driver.find_element(By.XPATH,
"""//*[#id="live-fullscreen"]/div[1]/div/div[4]/div[3]/section/div/button[2]""")
except NoSuchElementException:
return False
return True
if check_exists_by_xpath(True):
driver.find_element(By.XPATH,
"""//*[#id="live-fullscreen"]/div[1]/div/div[4]/div[3]/section/div/button[2]""").click()
time.sleep(3)
driver.find_element(By.XPATH,
'//div[#class="resize-wrap squad-player size0 default-layout"]').click()
time.sleep(0.5)
driver.find_element(By.XPATH,
'//section[#class="v-clarity-switcher"]').click()
time.sleep(10)
if driver:
driver.close()
driver.quit()
I stopped at this step
<div class="vcp-clarityswitcher"><section data-v-bdceacc0="" class="v-clarity-switcher"><svg data-v-bdceacc0="" aria-hidden="true" class="svg-icon clarity-icon icon-360P 360P"><use xlink:href="#icon-360P"></use></svg> <!----></section></div>

Related

May I know why it shows unable to locate element?

from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
driver = webdriver.Chrome('ChromeDriver')
driver.get("https://devbusiness.tunai.io/login")
time.sleep(2)
driver.maximize_window()
#log in credentials
username = driver.find_element(By.NAME, "loginUsername");
username.send_keys("kevin#tunai");
password = driver.find_element(By.NAME, "loginPassword");
password.send_keys("xxxxx");
login = driver.find_element(By.XPATH,"//*[#id='app']/div/div/div/div/div/div[2]/form/div[4]/button");
login.submit();
time.sleep(3)
driver.get("https://devbusiness.tunai.io/dashboard/salon_report_voucher")
time.sleep(3)
driver.find_element(By.XPATH, '//*[#id="packageTable"]/tbody[1]/tr/td[1]').click()
time.sleep(2)
driver.find_element(By.XPATH,'//*[#id="packageTable"]/tbody[1]/tr').click()
time.sleep(2)
#trigger the element before click
voucher = driver.find_element(By.XPATH, "//*[#id='packageTable']/tbody[2]/tr[1]")
driver.execute_script("arguments[0].click();", voucher)
time.sleep(2)
driver.find_element(By.XPATH, '//*[#id="packageTable"]/tbody[2]/tr[1]')
time.sleep(2)
#trigger the detail button
detail = driver.find_element(By.XPATH, "//*[#id='checkAll']")
driver.execute_script("arguments[0].click();", detail)
time.sleep(5)
driver.find_element(By.XPATH, "//*[#id='checkAll']")
time.sleep(5)
driver.find_element(By.XPATH, '//*[#id="voucherModal___BV_modal_body_"]/div/div/button[1]').click()
time.sleep(5)
I wanna click on the edit new price and enter a new price, save it and loop it. For now, I am not allow to enter the new price and proceed. I copied the Xpath and tried, but it failed so i m thinking because of the popout page. thats why it failed.
To click on Edit Price button. use webdriverwait() and wait for element to be clickable and following xpath.
Then wait for model to pop up and then enter the value.
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//div[#id='voucherModal___BV_modal_content_']//button[text()='Edit Price']"))).click()
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//div[#id='voucherEditModal___BV_modal_content_']//input[#data-maska-tokens]"))).click()
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//div[#id='voucherEditModal___BV_modal_content_']//input[#data-maska-tokens]"))).send_keys("1000")
you need to import below libraries.
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

selenium python: element not intreractable

The problem is when I am clicking the first name field, the click is working, but when I am sending the text to the field, it is showing me the error:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
Here is my code:
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.keys import Keys
s = Service("C:/Users/TUL/Desktop/cd/cd.exe")
driver = webdriver.Chrome(service=s)
driver.get('https://www.universityliving.com/')
driver.maximize_window()
time.sleep(3)
driver.find_element(By.XPATH, '/html/body/div[3]/div/div/div[2]/button').click()
time.sleep(1)
driver.find_element(By.XPATH, '/html/body/div[1]/div/div[2]/div[3]/div/div/a[1]/div/div/div').click()
time.sleep(2)
driver.switch_to.window(driver.window_handles[1])
driver.find_element(By.XPATH, "//div[#class='slick-slide slick-active slick-current']//div//img[#alt='Urbanest Carlton Melbourne']").click()
time.sleep(2)
driver.switch_to.window(driver.window_handles[2])
driver.find_element(By.XPATH, '/html/body/div[2]/div/div[2]/div[3]/div[2]/div/div[2]/div/div[3]/div/div/div[3]/div/div[3]/div/ul/li[2]/p').click()
driver.current_window_handle
driver.find_element(By.XPATH, '//*[#id="enquiryForm"]/div[1]/div[1]/div/div/label').click()
driver.find_element(By.XPATH, '//*[#id="enquiryForm"]/div[1]/div[1]/div/div/label').send_keys('h')
time.sleep(3)
What I am expecting is, if the field is clickable then it must be text acceptable also.

unable to locate element by XPATH on Tripadvisor

I don't know how to click on this image, I tried many things but it doesn't work. That says the XPATH is wrong.
what I want to click :
my code :
# TripAdvisor
driver.get("https://www.tripadvisor.fr/")
time.sleep(0.5)
driver.implicitly_wait(3)
driver.find_element(By.XPATH, '//*[#id="onetrust-reject-all-handler"]').click()
time.sleep(1.5)
driver.implicitly_wait(3)
if choices == "r":
driver.find_element(By.CSS_SELECTOR, '#lithium-root > main > div.cBOoN > div.rGQXC._T.ivvQp > div > div > div:nth-child(4) > a').click()
driver.implicitly_wait(1)
driver.find_element(By.XPATH, '/html/body/div[3]/div/form/input[1]').send_keys(city)
time.sleep(0.75)
driver.implicitly_wait(2)
driver.find_element(By.XPATH, '//*[#id="typeahead_results"]/a[1]').click()
driver.implicitly_wait(2)
try:
driver.find_element(By.XPATH, '//*[#id="onetrust-reject-all-handler"]').click()
except:
pass
time.sleep(2)
driver.find_element(By.XPATH, '//*[#id="component_48"]/div/div[2]/div[2]/div[3]/div/label').click()
time.sleep(1)
driver.implicitly_wait(2)
driver.find_element(By.XPATH, '//*[#id="component_36"]/div[1]/div[1]/div/span[2]/span').click()
time.sleep(1)
driver.implicitly_wait(2)
driver.find_element(By.XPATH, '//*[#id="component_48"]/div/div[2]/div[2]/div[1]/div/label').click()
driver.find_element(By.XPATH, '//*[#id="component_48"]/div/div[2]/div[2]/div[2]/div/label').click()
time.sleep(2)
driver.implicitly_wait(2)
driver.find_element(By.XPATH, '//*[#id="component_2"]/div/div[1]/div/span/div[1]/div[1]/span[2]/a').click()
I also tried with coordinates but that don't work.
Thank you for anyone who helps me.
You need to improve your locators and use WebDriverWait expected_conditions explicit waits instead of driver.implicitly_wait.
the following code works:
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = Options()
options.add_argument("start-maximized")
webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 10)
url = "https://www.tripadvisor.fr/"
driver.get(url)
wait.until(EC.element_to_be_clickable((By.XPATH, "//div[#data-test-target='nav-links']//a[contains(#href,'Restaurants')]"))).click()
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[data-test-attribute*='RESTAURANTS'] input[type='search']"))).send_keys("Paris")
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#typeahead_results a[href*='Restaurants']"))).click()
time.sleep(1)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "label[for='checkbox_5']"))).click()
time.sleep(4)
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[contains(text(),'Supprimer tous les filtres')]"))).click()
time.sleep(2)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "label[for='checkbox_3']"))).click()
time.sleep(2)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "label[for='checkbox_4']"))).click()
time.sleep(2)
wait.until(EC.presence_of_element_located((By.XPATH, "//a[contains(#href,'Review-')]//div[contains(#class,'carousel')]//span[#class]"))).click()
instead of digging through divs, you could try looping through elements that match a more specific xpath, like this
//a[contains(#href,"html")]//descendant::img[contains(#src,"https://media-cdn")]

Trying to click on Metamask Login Button and Nothing Happens - Selenium Python

I want to create a scraping program on the PvU site https://marketplace.plantvsundead.com/#/login
I've managed to open Chrome with the Metamask extension and to log in to metamask.
Now I need to login on to the PvU platform, but I can't click on the "Log in with MetaMask" button.
I've tried to click with:
1 -
driver.find_element(By.CSS_SELECTOR,"div.metamask.tw-flex.tw-items-center.tw-p-3.tw-cursor-pointer").click()
2 -
driver.find_element(By.XPATH, '//*[#id="__layout"]/div/div[2]/div/div[2]/div[1]/img')
3 -
element = WebDriverWait(driver, delay).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "div.metamask.tw-flex.tw-items-center.tw-p-3.tw-cursor-pointer")))
ac.move_to_element(element).click(element).perform()
No errors, but nothing happens.
Does anyone know what to do?
My code:
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
import sys
from selenium.webdriver.common.keys import Keys
from time import sleep
import asyncio
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
import time
def run_chrome():
#criando uma instância do chrome com o profile escolhido
options = Options()
options.add_argument("start-maximized")
options.add_argument("user-data-dir=C:\\Python")
driver = webdriver.Chrome(options=options)
ac = ActionChains(driver)
#abrindo o metamask e logando
driver.get('chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/home.html')
delay = 3 # seconds
try:
WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.XPATH, '//*[#id="password"]')))
print ("Page is ready!")
except TimeoutException:
print ("Loading took too much time!")
s_pass = "PASSWORD"
driver.find_element(By.XPATH, '//*[#id="password"]').send_keys(s_pass)
driver.find_element(By.XPATH, '//*[#id="app-content"]/div/div[4]/div/div/button/span').click()
#abrindo uma nova guia com o metamaks
EXTENSION_ID = 'nkbihfbeogaeaoehlefnkodbefgpgknn'
driver.execute_script("window.open('');")
driver.switch_to.window(driver.window_handles[1])
driver.get('chrome-extension://{}/popup.html'.format(EXTENSION_ID))
#abrindo o PvU
driver.switch_to.window(driver.window_handles[0])
driver.get('https://marketplace.plantvsundead.com/#/login')
#I CAN'T PASS THIS
try:
WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.XPATH, '//*[#id="__layout"]/div/div[2]/div/div[2]/div[1]/img')))
print ("Page is ready!")
except TimeoutException:
print ("Loading took too much time!")
try:
content = driver.find_element(By.CSS_SELECTOR,"div.metamask.tw-flex.tw-items-center.tw-p-3.tw-cursor-pointer")
print ("Page is ready!")
except TimeoutException:
print ("Loading took too much time!")
content.click()
element = WebDriverWait(driver, delay).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "div.metamask.tw-flex.tw-items-center.tw-p-3.tw-cursor-pointer")))
ac.move_to_element(element).click(element).perform()
time.sleep(2)
driver.switch_to.window(driver.window_handles[1])
time.sleep(2)
run_chrome()
THANK YOU
Try this one, this will work for you:
ele=driver.find_element_by_xpath("//*[#id='__layout']//p[starts-with(normalize-space(),'Log in with MetaMask')]")
ele.click()
Tried this locally and the click worked for me.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
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
driver = webdriver.Chrome()
driver.get("https://marketplace.plantvsundead.com/#/login")
item = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//div[contains(#class, "metamask tw-flex tw-items-center tw-p-3")]')))
time.sleep(0.15)
item.click()
But I got a popup saying 'Please install metamask'. Have a look here to solve that issue.
https://dev.to/ltmenezes/automated-dapps-scraping-with-selenium-and-metamask-2ae9

How to click recaptchaV2's Solve the challenge button using Selenium and Python

I'm trying to interact with the recaptchaV2 Solve the challenge button on image verification popup using Selenium and Python.But meet some problem.By the way,I use buster chrome extension to bypass the recaptcha.Hope can help me.Thank you~
from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
chrome_options = webdriver.ChromeOptions()
chrome_options.add_extension('~/Library/Application Support/Google/Chrome/Default/Extensions/mpbjkejclgfgadiemmefgebjfooflfhl/1.1.0_0.crx')
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("https://www.google.com/recaptcha/api2/demo")
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src^='https://www.google.com/recaptcha/api2/anchor']")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span#recaptcha-anchor"))).click()
driver.switch_to.default_content()
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[title='recaptcha challenge']")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#solver-button"))).click()
problem like
chrome_options = webdriver.ChromeOptions()
Is outdated use Options.
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
Also the audio button is
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#recaptcha-audio-button"))).click()
Not
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#solver-button"))).click()
It also detects automation so use
chrome_options.add_argument('--disable-blink-features=AutomationControlled')
Evil company was change class name in [challenge]
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[title='recaptcha challenge expires in two minutes']")))
driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
driver.get('https://www.google.com/recaptcha/api2/demo')
element_present = driver.find_element(By.XPATH, '//*[#title="reCAPTCHA"]')
driver.switch_to.frame(element_present)
element_present = EC.presence_of_element_located((By.XPATH, '//*[#id="recaptcha-anchor"]/div[1]'))
WebDriverWait(driver, 15, poll_frequency=POLL_FREQUENCY).until(element_present).click()
driver.switch_to.default_content()
time.sleep(5)
element_present = driver.find_element(By.XPATH, "/html/body/div[2]/div[4]/iframe")
driver.switch_to.frame(element_present)
try:
buttonHolderElement = driver.find_element(By.XPATH, '//*[#id="rc-imageselect"]/div[3]/div[2]/div[1]/div[1]/div[4]')
actions = ActionChains(driver)
actions.move_to_element(buttonHolderElement)
actions.click(buttonHolderElement)
actions.perform()
except:
pass

Categories