Selenium-Calendar Picker-选择当日NoSuchElementException Python 3

时间:2018-08-30 19:18:26

标签: python-3.x selenium nosuchelementexception

问题出在我浏览页面的方法上。我必须选择实际日历,然后选择当前日期。以下代码是更新的正确代码。

from selenium import webdriver
import time


driver = webdriver.Firefox()

#navigates to website 
driver.get('https://www.sosnc.gov/online_services/search/by_title/_Business_Registration_changes')

#select calendar
driver.find_element_by_xpath('/html/body/div[2]/main/article/div/form/article/section/div/div[2]/label').click()
time.sleep(3)

#select current calendar date
driver.find_element_by_css_selector('.ui-datepicker-today').click()
time.sleep(2)

#select and click search button
driver.find_element_by_xpath('//*[@id="Search"]').click()

1 个答案:

答案 0 :(得分:0)

我已将上面的代码更新为正确的代码,并提供了解决方案的说明。

from selenium import webdriver
import time


driver = webdriver.Firefox()

#navigates to website 
driver.get('https://www.sosnc.gov/online_services/search/by_title/_Business_Registration_changes')

#select calendar
driver.find_element_by_xpath('/html/body/div[2]/main/article/div/form/article/section/div/div[2]/label').click()
time.sleep(3)

#select current calendar date
driver.find_element_by_css_selector('.ui-datepicker-today').click()
time.sleep(2)

#select and click search button
driver.find_element_by_xpath('//*[@id="Search"]').click()