'How do I grab an element and a class with selenium (Python)?
I'm trying to do some automation testing where I will need to grab an element to choose the right quality video. The problem here is that I tried CSS Selector, Class Name, and XPath and nothing is working as I want it.
Does anyone know a better way to choose the quality of a video inside by using selenium and python?
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from random import *
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException, TimeoutException
import threading
import time
from idlelib import browser
def get_driver_and_webpage():
options = webdriver.ChromeOptions()
options.add_argument("--incognito")
#chrome_options.add_argument('--headless')
#chrome_options.add_argument('--no-sandbox')
browser = webdriver.Chrome(executable_path= "C:\\Program files (x86)\\ChromeDriver\\chromedriver.exe", chrome_options=options)
browser.get('https://ampdemo.azureedge.net/azuremediaplayer.html?url=%2F%2Famssamples.streaming.mediaservices.windows.net%2F49b57c87-f5f3-48b3-ba22-c55cfdffa9cb%2FSintel.ism%2Fmanifest&muted=true&aes=true&wallClockDisplayEnabled=true&useLocalTimeZone=true')
wait = WebDriverWait(browser, 10)
browserr = wait.until(EC.presence_of_element_located(
(By.CLASS_NAME, "vjs-menu-content")))
cclick = wait.until(EC.element_to_be_clickable(
(By.CLASS_NAME, "aria-lebel")))
browser.click()
time.sleep(randint(10, 15))
browser.clear()
time.sleep(randint(10, 15))
cclick.click()
print("search-cclick has been clicked")
time.sleep(randint(15, 20))
time.sleep(200)
browser.quit()
Number = 1 # Number of browsers to be open
thread_list = list()
for i in range(Number):
t = threading.Thread(name='Test {}'.format(i), target=get_driver_and_webpage)
t.start()
time.sleep(1)
print(t.name + ' started!')
thread_list.append(t)
for thread in thread_list:
thread.join()
print('Testing is completed and done')
Solution 1:[1]
If I read the question and the page correctly, you can read content of the element from this CSS query to see the selected quality:
div.amp-quality-control li[aria-checked='true']
You can use the CSS query without the aria-checked='true'
to look for the available qualities reported by the page"
div.amp-quality-control li
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | David Culbreth |