Python Selenium select div类带有空白

时间:2018-10-20 21:53:58

标签: python selenium-webdriver xpath

尝试选择包含一些空格的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()

1 个答案:

答案 0 :(得分:2)

您的问题与“空白” /“空白” 没有关系,因为选择器应该可以正常工作...如果DOM中存在元素。尝试等到元素出现在DOM中并变为可点击状态:

while(!terminer)