Python:WebDriverWait按钮不起作用

时间:2017-10-25 15:53:29

标签: python selenium selenium-webdriver

点击show-more-results按钮。我已经使用了WebDriverWait,因此它允许页面加载但没有用。

HTML:

 <div class="powerball_stats_list">
    <div id="loading-box"></div>
    <button id="more-btn" class="btn_list_more" type="button">more data</button>
 </div>

蟒:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

while True:
    try:
        WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH, "//button[@id='more-btn' class='btn_list_more' type='button']")))
        WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.XPATH, "//button[@id='more-btn' class='btn_list_more' type='button']")))
        click=WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[@id='more-btn' class='btn_list_more' type='button']")))
        try:
            click.click()
        except WebDriverException:
            print "Page not loaded Correctly. Try again."
            break
    except (TimeoutException, StaleElementReferenceException, ElementNotVisibleException, NoSuchElementException):
        break

1 个答案:

答案 0 :(得分:1)

您的XPath不正确,因为XPath中不允许使用这些谓词class='btn_list_more' type='button'。试试

"//button[@id='more-btn' and @class='btn_list_more' and @type='button']"