用空格选择div类

2024-10-03 15:27:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我在尝试选择一个包含一些空格的div标记类时遇到了一个问题。你知道吗

页面结构如下:

<div class="sadasd-dashboardtab even asdasd-syndicating_from_my_file" id="124121_1540012412412414">
    <div id="124121_154006585856856858">
        <span class="label">Syndicating From My File</span>
        <button class="column-dropdown" title="Click for more tab options"></button>
    </div>
</div>

这是我对这部分代码的尝试:

#syndicating_button = driver.find_element_by_xpath("//span[text()='Syndicating From My File']")  
#syndicating_button = driver.find_element_by_xpath("//div[@class='yui3-dashboardtab even s-tab-syndicating_from_my_site']")
syndicating_button = driver.find_element_by_css_selector("div.yui3-dashboardtab.even.s-tab-syndicating_from_my_site")                                               
syndicating_button.click()

Tags: fromdividbymydriverbuttonelement
1条回答
网友
1楼 · 发布于 2024-10-03 15:27:53

您的问题与“空白”/“空白”无关,因为您的选择器应该工作良好。。。如果DOM中存在元素。尝试等待元素出现在DOM中并可单击:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC

wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Syndicating From My Site']"))).click()

相关问题 更多 >