2014-12-19 124 views
-1

這是我的源代碼:硒如何點擊

<a id="form_week:btn_before" title="Précedent" onclick="var cf = function(){disableLink('btn_before');};var oamSF = function(){return oamSubmitForm('form_week','form_week:btn_before');};return (cf()==false)? false : oamSF();" href="#"> 

如何點擊該鏈接?

編輯:

我測試您的三個答案,但

mydriver.find_element_by_xpath('//a[@title="Précedent"]').click() 
    File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 230, in find_element_by_xpath 
    return self.find_element(by=By.XPATH, value=xpath) 
    File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 662, in find_element 
    {'using': by, 'value': value})['value'] 
    File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 173, in execute 
    self.error_handler.check_response(response) 
    File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 166, in check_response 
    raise exception_class(message, screen, stacktrace) 
selenium.common.exceptions.NoSuchElementException 

解決:

這是我的錯,我沒有看到,元素a,是在一個iframe中。

mydriver.switch_to_frame(mydriver.find_element_by_xpath("//iframe")); 
mydriver.find_element_by_id('form_week:btn_before').click() 

回答

0

這你如何做到這一點:

from selenium import webdriver 

driver = webdriver.Firefox() 
driver.get(url) 
driver.find_element_by_id('form_week:btn_before').click() 
1

它將點擊元素a,標題爲 '先例'上:

driver.find_element_by_xpath('//a[@title="Précedent"]').click() 
0

你可以使用點擊命令,並通過元素ID

selenium.click("form_week:btn_before") 
0

導入WebDriverWaitexpected_conditions,這會告訴您的驅動程序在嘗試查找按鈕時等待最多60秒。然後嘗試使用ID:

WebDriverWait(
    webdriver, 
    60 
).until(
    expected_conditions.visibility_of_element_located(
     (By.ID, 'form_week:btn_before')) 
).click()