python webdriver chromedriver:无法点击按钮

时间:2017-06-26 18:48:44

标签: python button webdriver selenium-chromedriver

<div class="dialog-ft">  
    <button mx-click="submit" data-spm-click="gostr=/alimama.11;locaid=decf8333e" class="btn btn-brand w100 mr10">confirm</button>   
    <button mx-click="close" data-spm-click="gostr=/alimama.11;locaid=d4df4de16" class="btn btn-gray w100">cancel</button> 
 </div>

页面上有2个按钮,我需要点击第一个来继续我的逻辑。我写了一些代码:'

def locate_element_by_xpath(xdriver, xpath):  
element = None
try:
    element = WebDriverWait(xdriver, 60).until(
        EC.presence_of_element_located((By.XPATH, xpath)))
except StaleElementReferenceException as e:
    raise e
if element:
    return element
else:
    return False

driver.execute_script("arguments[0].click();",
                            locate_element_by_xpath(driver, '//*[@id="magix_vf_code"]/div/div[1]/ul/li[1]'))

我可以通过将print .text测试为'confirm'

来确保xpath正常工作

我得到了TimeoutException(message, screen, stacktrace) Error.

我也尝试了原来的方法并得到了同样的错误:

dialog.find_element_by_class_name('dialog-ft').find_element_by_tag_name('button').click()

任何人都可以帮忙看一下吗?谢谢。

0 个答案:

没有答案