我如何使用Selenium(Python)来获取元素和类?

问题描述 投票:0回答:1

我正在尝试进行一些自动化测试,在这里我需要掌握一些要素以选择质量合适的视频。这里的问题是我尝试了CSS选择器,类名和XPath,但没有按我希望的那样工作。

有人知道使用硒和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')
python selenium testing automation qa
1个回答
0
投票

如果我正确阅读了问题和页面,则可以从此CSS查询中读取元素的内容,以查看所选的质量:

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

您可以使用不带aria-checked='true'的CSS查询来查找页面报告的可用质量“

div.amp-quality-control li
© www.soinside.com 2019 - 2024. All rights reserved.