简体   繁体   English

使用PhantomJS在硒中输入日期

[英]Date entry in selenium using PhantomJS

I am finding it difficult to enter date into a date field box. 我发现很难在日期字段框中输入日期。 I am using selenium with PhantomJS. 我在PhantomJS中使用硒。

This is what I've tried so far: 到目前为止,这是我尝试过的:

def dobInfo(driver,dob):
    dobentry = driver.find_element_by_xpath("/html[1]/body[1]/div[3]/div[1]/div[3]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/div[1]/div[3]/div[1]/div[1]/div[1]/form[1]/div[5]/label[1]")
    Actions(driver).move_to_element(dobentry).wait(0.3).click().perform()
    driver.save_screenshot("clickedonDOB.png")

    elem = driver.find_element_by_xpath("/html[1]/body[1]/div[3]/div[1]/div[3]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/div[1]/div[3]/div[1]/div[1]/div[1]/form[1]/div[5]/input[1]")
    driver.save_screenshot("clickedonDOB2.png")
    elem.send_keys(dob)

I have been saving screenshots, and what I can see is that the field is not being selected to show DD/MM/YYYY replacing the Date of Birth Label, when trying to click on element dobentry to then enter dob in 'dd/mm/yyyy' format. 我一直在保存屏幕截图,可以看到的是,当尝试单击元素dobentry然后在'dd / mm /中输入dob时,没有选择该字段来显示DD / MM / YYYY来代替出生日期标签。 yyyy'格式。 I've tried clicking on input and on label, and both do not seem to click but return no error. 我尝试单击输入和标签,两者似乎都没有单击,但没有返回错误。

xPath /html[1]/body[1]/div[3]/div[1]/div[3]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/div[1]/div[3]/div[1]/div[1]/div[1]/form[1]/div[5]/input[1]" xPath / html [1] / body [1] / div [3] / div [1] / div [3] / div [1] / div [1] / div [1] / div [1] / div [1 ] / div [2] / div [1] / div [1] / div [3] / div [1] / div [1] / div [1] / form [1] / div [5] / input [1 ]”

returns: 返回:

< input id="b11eba51-2d36-4fd4-8f73-0bf2bbca3b12" type="date" placeholder="Date of Birth" value="" name="dateOfBirth" data-componentname="dateOfBirth" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" data-ddlabel="dd" data-mmlabel="mm" data-yyyylabel="yyyy" xpath="1">

The url is https://www.nike.com/gb/launch/ (Have to click on 'join/log' in then 'join now' to get form) 网址为https://www.nike.com/gb/launch/ (必须单击“加入/登录”,然后单击“立即加入”以获取表格)

Thanks :) 谢谢 :)

Can you try using this as a selector input[id="fe49fe96-c81e-452e-b7ae-9a32ab4e5702"] ? 您可以尝试将其用作选择器输入[id =“ fe49fe96-c81e-452e-b7ae-9a32ab4e5702”]吗?

I was able to access the element via jQuery 我能够通过jQuery访问元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM