点击日期框,清除值并请求新数据。我试图点击日期字段,但我没有看到日历弹出应有的状态。我怎么能这样做?
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)
问题在于定位器,因为当您尝试运行上面的代码时,它会抛出错误"元素不可点击其他元素会收到点击"
只需在代码中添加execute_script()
即可使用
也不要在编码中使用保留关键字,因为filter是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)