I want to open and login 5 tabs concurrently without delay in between in tabs. I have tried:
import threading
import time
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
def openurl(threadId):
print(threading.currentThread().getName(),' Thread')
url = ('https://www.facebook.com/')
print(url)
driver.execute_script("window.open('{0}')".format(url))
#driver.title(threadId)
time.sleep(0.1)
driver.set_window_size(920, 680)
driver.find_element(By.ID, "email").send_keys("xx")
driver.find_element(By.ID, "pass").send_keys("yy")
driver.find_element(By.ID, "loginbutton").click()
if __name__=='__main__':
driver = webdriver.Chrome()
windows_before = driver.current_window_handle
for i in range(5):
t1 = threading.Thread(name=i,target=openurl, args=(i,))
t1.start()
t1.join()
but it is throwing:
Traceback (most recent call last): File "C:\Users\1024983\AppData\Local\Programs\Python\Python37\lib\threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "C:\Users\1024983\AppData\Local\Programs\Python\Python37\fb-thread.py", line 30, in openurl driver.find_element(By.ID, "email").send_keys("xx") File raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="email"]"} (Session info: chrome=78.0.3904.108)
If I increased sleep time, there is a delay in-between tabs. I tried to navigate using driver.title but my case title is same for all tabs.