0

I have to add stopwatch to my script

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

start = time.clock()

driver = webdriver.Firefox()
driver.get('https://ebay.com')

after this code it should stay for a while(5 seconds), than do other staff, like this:

element = driver.find_element_by_id("username")
element.send_keys("some text")

How to do it?

9
  • You need to use waits then, which will wait until element present. Commented Jul 27, 2017 at 13:45
  • @SaurabhGaur I found "until". Can i use it like, Until appearing element_by_id("username"). Can you show how to do it, please Commented Jul 27, 2017 at 13:49
  • there are many example around it, follow this or this..Thanks Commented Jul 27, 2017 at 13:54
  • @NurislomTuraev Why do you want to wait for 5 secs? How about providing the username as soon as the field is available? Commented Jul 27, 2017 at 14:21
  • @DebanjanB Because I want to use it on many websites, even where has cloudflare protection. So thats why I need it. Commented Jul 28, 2017 at 5:37

1 Answer 1

1

I spent many hours and with help of God and many people from StackOverflow, I finally solved it.

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException

driver = webdriver.Firefox()
driver.get(''https://ebay.com'')
delay = 30

try:
    myElem = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.ID, 'username')))
    element = driver.find_element_by_id("username")
    element.send_keys("some text")
except TimeoutException:
    print ("Loading took too much time!")

It would be the best, in my opinion.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.