0
start_time = time.time()
myElem = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.XPATH,
    '/html/body/app-root/div[1]/div[1]/div[3]/div[2]/div[1]/div/app-home/div/div[1]/app-slider/div/ngx-siema/div/div/div[4]/ngx-siema-slide/div[1]')))
x = ("%s" % (time.time() - start_time))
roundE = float(x)
print(roundE)

when I print Rounde output is 0.016000032424926758 is there any way to get 1 seconds ? ?

4
  • Your roundE variable is float. Try to cast it to int Commented Apr 8, 2021 at 11:17
  • print(round(roundE)) Commented Apr 8, 2021 at 11:18
  • ValueError: invalid literal for int() with base 10: ' Commented Apr 8, 2021 at 11:18
  • You are converting a float to str which isn't needed, just use round(time.time() - start_time) Commented Apr 8, 2021 at 11:19

4 Answers 4

5

You can use ceil() function from the math library.

import math
roundE = math.ceil(x)
Sign up to request clarification or add additional context in comments.

Comments

0

To convert your output to integer you just can use

int(roundE)

But in your case just converting to int is not solution.

roundE = 1  if roundE < 0.01  else int(roundE)

Or otherwise we need more info about your request.

Comments

0

I'm not sure I understood your question correctly but if you want 0.016000032424926758seconds to be rounded to 1 second, I would use : print(ceil(roundE)).

Make sure to import math, if not already done.

Comments

0
from datetime import datetime

a = datetime.now()

# Your codes to get data from selenium

b = datetime.now()

d = b - a # yields a timedelta object
d.seconds

1 Comment

Could you elaborate more your answer? I was be flagged to deletion for low quality answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.