2017-10-20 116 views
0

我必须自动从日期选择器中选择一个日期。我可以点击该字段并输入日期。在Firefox中,我能够使用按键键入日期,而当在Chrome上运行相同的测试提供了以下错误:如何使用机器人框架中的按键发送日期在铬日历弹出窗口

WebDriverException: Message: unknown error: cannot focus element 
    (Session info: chrome=62.0.3202.62) 
    (Driver info: chromedriver=2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c5810906a),platform=Windows NT 10.0.15063 x86_64) 

我尝试使用按键之前设置的焦点。设置焦点传递,但当它试图按键,我得到这个错误。

我的代码看起来像这样(能正常工作在Firefox):

Click Element xpath=//div[@class='ant-calendar-date-input-wrap'] 
    press key xpath=//div[@class='ant-calendar-date-input-wrap']|{date_to_select} 

[enter image description here

+1

请将代码放在“代码”使其更易于阅读和检查错误。另外,根据Todor(https://stackoverflow.com/questions/43790516/cant-press-enter-in-selenium2library),你需要第二个参数。我在代码中看不到它。 –

+0

感谢布兰登,第二个参数是一个变量$ {date_to_select}。我实际上通过使用'输入文本'而不是'发送密钥'找到了解决方法。 – Magicofcolors

+0

不是没有美元符号在它前面。 –

回答

0

我发现一种解决方法通过使用“输入文本”,而不是发送键chrome.Here是工作的代码: 输入文本xpath = // * [@ class ='ant-calendar-date-input-wrap']/input $ {date_to_select}

相关问题