Python Selenium无法单击字段 [英] Python selenium unable to click field

查看:126
本文介绍了Python Selenium无法单击字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试请求以后可以删除的数据.我将日期写在文本字段中,但是当我发送请求时,它不会根据日期进行更新.我正在尝试单击日期字段,但是我没有看到日历弹出的样子.我该怎么办?

I'm trying to request data that I can later scrap. I write the dates in the text field but when I send the request, it does not update according to the dates. I'm trying to click the date field, but I don't see the calendar pop up as it should. How can i go about this?

from selenium import webdriver
driver = webdriver.Firefox()
driver.get('https://www.fxstreet.com/economic-calendar')

time.sleep(10)

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

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

#set start and end time
driver.find_element_by_xpath("//input[contains(@id,'fxit-start-advance')]").click()
driver.find_element_by_xpath("//input[contains(@id,'fxit-start-advance')]").send_keys("01/01/2017")

driver.find_element_by_xpath("//input[contains(@id,'fxit-end-advance')]").click()
driver.find_element_by_xpath("//input[contains(@id,'fxit-end-advance')]").send_keys("06/01/2017")


#select countries

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

#refresh your results
driver.find_element_by_id('fxit-filterbutton').click()

推荐答案

我尝试了您的代码,它对我来说正常工作.我能够看到压光机打开并输入日期. 一点-您可能希望在.click()和.send_keys()之间包含.clear(),因为输入框不会自动清除-这可能就是为什么如果进行验证寻找就看不到日期更新的原因正确的日期格式.

I tried your code and it works correctly for me. I am able to see the calender open and input the date. One point - you may want to include a .clear() between your .click() and .send_keys() as the input box does not automatically clear - this may be why you are not seeing your date update if there is validation looking for a correct date format.

这篇关于Python Selenium无法单击字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆