2015-03-03 112 views
-2

我一直在試圖找到一個嵌套的按鈕元素(<button class="dwnload_xls"),並點擊它,但沒有這樣做。有人可以幫助我嗎? 我已經嘗試使用以下(單獨),但他們都只是給了同樣的答覆:無法找到使用硒webdriver按鈕元素

無法找到元素

我的代碼:

frame = WebDriverWait(browser, 30).until(lambda x: x.find_element_by_xpath(".//*[contains(@class, 'downloadxlsform')]//div[contains(@class,'downloadform')]//button[contains(@class, 'dwnload_xls')]")) 

HTML代碼:

​​

回答

1

你可以讓硒找到按鈕並通過submit()提交表單:

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

form = WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "form.downloadxlsform"))) 
form.submit() 

此外,如果形式是iframe裏面你需要switch to it first

driver.switch_to.frame('frame_name')