2017-07-04 84 views
-1

我點擊日期框,清除值並請求新數據。我試圖點擊日期字段,但我沒有看到日曆彈出,因爲它應該。我該如何解決這個問題?硒問題

from selenium import webdriver 
from selenium.webdriver.common.keys import Keys 

driver = webdriver.Firefox(executable_path='/home/usch/Desktop/PyCharm/Project/geckodriver') 

#load up website 
driver.get('https://www.fxstreet.com/economic-calendar') 

time.sleep(10) 

#close popup 
popup = driver.find_element_by_xpath('//button[@aria-label="Close Modal"]') 
popup.click() 

#click filter options 
filter = driver.find_element_by_id('fxit-advlink') 
filter.click() 


#set start and end time 
startDate = driver.find_element_by_xpath("//input[contains(@id,'fxit-start-advanced')]") 
startDate.send_keys(Keys.ENTER) 
startDate.clear() 
startDate.send_keys("01/02/2017") 
startDate.send_keys(Keys.ENTER) 

endDate = driver.find_element_by_xpath("//input[contains(@id,'fxit-end-advanced')]") 
endDate.send_keys(Keys.ENTER) 
endDate.clear() 
endDate.send_keys("06/01/2017") 
endDate.send_keys(Keys.ENTER) 

#driver.switch_to.default_content() 
#select countries 

#select data type 
category = driver.find_element_by_xpath('//a[@class="fxst-selectall" and @data-name="fxst-category"]').click() 


#refresh your results 
refresh = driver.find_element_by_xpath('//a[@id="fxit-filterbutton"]').click() 
+0

日曆顯示和消失非常快因爲它是硒它必須讓事情變得快速,但是你是否想等待一段時間? –

+0

即使我一行一行地運行,日曆不會彈出 –

+0

我添加time.sleep(5)每次設置後,它彈出正確,所以我不認爲它與您的代碼 –

回答

0

的問題是定位器,當您嘗試運行它拋出錯誤「元素不能點擊其他元素將獲得單擊」

只是在你的代碼添加execute_script()它會工作

上面的代碼

作爲過濾器是在Python

filter1 = driver.find_element_by_css_selector('#fxit-advlink') 
driver.execute_script("arguments[0].click();", filter1) 

category = driver.find_element_by_xpath('//a[@class="fxst-selectall" and @data-name="fxst-category"]') 
driver.execute_script("arguments[0].click();", category) 

#refresh your results 
refresh = driver.find_element_by_xpath('//a[@id="fxit-filterbutton"]') 
driver.execute_script("arguments[0].click();", refresh) 
關鍵字也從來沒有使用你的編碼保留關鍵字
+0

這是正確的答案 –

+0

比請接受它作爲答案 – thebadguy