如何使用selenium python创建播放列表

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

我正在创建一个用selenium创建youtube播放列表的脚本但我被困在这里,我尝试了很多方法,但所有这些都不起作用!有人能帮我吗?谢谢

<input type="text" class="Mf-jm-Qc-qb d-Rb" aria-label="Search terms" style="width: 325px;">

我试过了 :

1

driver.find_element_by_xpath("//input[@class='Mf-jm-Qc-qb d-Rb']").send_keys("https://www.youtube.com/watch?v=NliYy7iqh-U")

2

driver.find_element_by_xpath("//input[@type='text']").send_keys("https://www.youtube.com/watch?v=NliYy7iqh-U")

3

driver.find_element_by_css_selector(".Mf-jm-Qc-qb").send_keys("https://www.youtube.com/watch?v=NliYy7iqh-U")

4

driver.find_element_by_class_name("Mf-jm-Qc-qb d-Rb").send_keys("https://www.youtube.com/watch?v=NliYy7iqh-U")
python selenium xpath css-selectors webdriverwait
1个回答
1
投票

该元素看起来是一个动态元素,因此您必须为所需的elementToBeClickable引入WebDriverWait,并且您可以使用以下任一解决方案:

  • 使用CSS_SELECTORWebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[aria-label='Search terms'][type='text']"))).send_keys("https://www.youtube.com/watch?v=NliYy7iqh-U")
  • 使用XPATHWebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@aria-label='Search terms' and @type='text']"))).send_keys("https://www.youtube.com/watch?v=NliYy7iqh-U")
  • 注意:您必须添加以下导入: from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
© www.soinside.com 2019 - 2024. All rights reserved.