ValueError:时间数据“”与格式不匹配

时间:2019-06-16 06:54:43

标签: python selenium strptime

我正在尝试从Selenium Xpath获取字符串,它是日期字符串,格式为10-08-2019,然后通过strptime()将其传递到日期格式。但是我遇到了

错误
a=input("give your list to be sorted : ")
a.split()
a.sort()
print(a)

下面是我的代码。

give your list to be sorted : 3 2 44 5 6 99 1
Traceback (most recent call last):
  File ................................................................., line 3, in <module>
    a.sort()
AttributeError: 'str' object has no attribute 'sort'

Process finished with exit code 1

=====================================

for each in list:
p = Process(target=stat, args=(each,))
p.start()
p.join()

================================================ ==========

"ValueError: time data '' does not match format"

from datetime import datetime
from datetime import date
import datetime

d4=driver.find_element_by_xpath('/html/body/form/table/tbody/tr/td').text
print d4 
d3=datetime.datetime.strptime(d4,"%d-%m-%Y")
d3=d3.strftime("%d-%m-%Y")
print d3

如果我不从Selenium Xpath获取它就执行成功。 PSB

Output.
10-08-2019
10-08-2019
E
------------------------------------------------------------------
Test Environment Destroyed
Run Completed at :2019-06-16 10:42:08.101000

输出。

ERROR: test_CRMDSAA (__main__.CRMDSAA)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:/WebAutomation/WebAutomation/Test/FunctionalScripts/CRMandOtherUserPortal/test_E2EP2-344CrmDisconnectionSubscriptionAnyAccount.py", line 92, in test_CRMDSAA
    d3=datetime.datetime.strptime(d4,"%d-%m-%Y")
  File "C:\Python27\lib\_strptime.py", line 325, in _strptime
    (data_string, format))
ValueError: time data '' does not match format '%d-%m-%Y'

0 个答案:

没有答案