使用PhantomJS在硒中输入日期

时间:2018-04-11 20:12:03

标签: javascript html selenium selenium-webdriver phantomjs

我发现很难在日期字段框中输入日期。我正在使用含有PhantomJS的硒。

这是我到目前为止所尝试的:

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)

我一直在保存屏幕截图,我可以看到该字段未被选中显示DD / MM / YYYY替换出生日期标签,当尝试点击元素dobentry然后在'dd中输入dob / mm / yyyy'格式。我试过点击输入和标签,两者似乎都没有点击但没有返回错误。

XPATH  / HTML [1] /体[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] /形式[1] / DIV [5] /输入[1] “

返回:

< 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">

网址为https://www.nike.com/gb/launch/(必须点击“加入/登录”然后“立即加入”才能获得表单)

谢谢:)

1 个答案:

答案 0 :(得分:0)

您可以尝试将其用作选择器输入[id =&#34; fe49fe96-c81e-452e-b7ae-9a32ab4e5702&#34;]?

我能够通过jQuery

访问该元素