簡體   English   中英

如何使用 selenium (Python) 獲取元素和類?

[英]How do I grab an element and a class with selenium (Python)?

我正在嘗試進行一些自動化測試,我需要獲取一個元素來選擇合適質量的視頻。 這里的問題是我嘗試了 CSS Selector、Class Name 和 XPath,但沒有任何效果。

有誰知道使用 selenium 和 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')

如果我正確閱讀了問題和頁面,您可以從此 CSS 查詢中讀取元素的內容以查看所選質量:

div.amp-quality-control li[aria-checked='true']

您可以使用沒有aria-checked='true'的 CSS 查詢來查找頁面報告的可用質量”

div.amp-quality-control li

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM