4

How can I open 5 urls simultaneously on a single browser? In addition, the script has to browse one by one through these 5 urls by performing the following tasks:

  • adding information on a field
  • select a CTA button
  • then click on a Send button

1 url must have a tab, so in total it should have 5 tabs running one by one.

here's my code but it didn't work Thank you for your help

from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver


driver = webdriver.Chrome(ChromeDriverManager().install())
driver.maximize_window()
driver.delete_all_cookies()

urls = ["https://business.google.com/u/0/edit/l/10199720925622488243?hl=fr",
        "https://business.google.com/u/0/edit/l/13532588171385373346?hl=fr",
        "https://business.google.com/edit/l/18307083220547614220",
        "https://business.google.com/u/0/edit/l/08603059593698723407?hl=fr",
        "https://business.google.com/edit/l/00810825496818981035"]
for posts in urls:
    a = driver.execute_script("window.open('');")
    driver.get(a)

1 Answer 1

4
from selenium import webdriver
from selenium.webdriver.support.ui import Select
import time

driver = webdriver.Chrome(executable_path=r"C:\Users\prave\Downloads\travelBA\chromedriver.exe")


driver.maximize_window()
driver.delete_all_cookies()

urls = ["https://business.google.com/u/0/edit/l/10199720925622488243?hl=fr",
        "https://business.google.com/u/0/edit/l/13532588171385373346?hl=fr",
        "https://business.google.com/edit/l/18307083220547614220",
        "https://business.google.com/u/0/edit/l/08603059593698723407?hl=fr",
        "https://business.google.com/edit/l/00810825496818981035"]
for posts in range(len(urls)):
    print(posts)
    driver.get(urls[posts])    
    if(posts!=len(urls)-1):
       driver.execute_script("window.open('');")
       chwd = driver.window_handles
       driver.switch_to.window(chwd[-1])

// you can move to specific handle    
chwd = driver.window_handles
print(chwd)

find the window handle and switch to it

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

2 Comments

I got this error at <<for posts in (len(urls)):>> ERROR: => for posts in (len(urls)): TypeError: 'int' object is not iterable
Read it properly it's not Len() it's range(Len()

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.