我的HTML代码如下:
<button aria-label="Nur zuhören" aria-disabled="false" class=
"jumbo--Z12Rgj4 buttonWrapper--x8uow audioBtn--1H6rCK">
我想用以下Python代码单击按钮:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
wait(driver, 20).until(EC.element_to_be_clickable((By.CLASS_NAME, "jumbo--Z12Rgj4 buttonWrapper--x8uow audioBtn--1H6rCK"))).click
但它不起作用
如果要查找具有多个类名的元素,可以使用XPATH
我将html简化为
<button class="aaa bbb ccc">
然后您可以使用
(By.XPATH, "//button[contains(@class, 'aaa') and contains(@class, 'bbb') and contains(@class, 'ccc')]")
查找此按钮Selenium无法通过
class name
找到multiple class names
,而是使用css selector.
试试下面的css选择器
或
希望这有帮助
尝试在webelement中捕获元素,然后尝试执行预期条件命令。应该行得通
单击驱动程序。按类名称查找元素(jumbo Z12Rgj4按钮Rapper x8uow audioBtn 1H6rCK)
等待(驱动程序,20)。直到(EC.元素可点击(点击元素点击)))
等待(驱动程序,20)。直到(EC.元素可点击((按.CLASS\u名称,“jumbo Z12Rgj4按钮Rapper x8uow audioBtn 1H6rCK”)。点击
。单击可能不是下拉列表中的选项,因为它包含2个位置参数
相关问题 更多 >
编程相关推荐