Now able to open multiple windows selenium common exceptions WebDriverException invalid session id

0 votes

I am trying to open a window, do some scraping and close it. I am trying to do this in a loop. This is the code:

from selenium import webdriver
from bs4 import BeautifulSoup
import pandas as pd
import time

chromedriver = "F:\omkar\Download\chromedriver"
driver = webdriver.Chrome(chromedriver)

for i in range(0,3):
    url="https://www.edureka.co/community/users?start=" + str(i*200)
    driver.get(url)
    time.sleep(3)
    driver.close()

It opens the first window with no problem but the second window doesn’t open. I get this error

selenium.common.exceptions.WebDriverException: Message: invalid session id
Apr 6, 2019 in Python by Raj
9,629 views

1 answer to this question.

0 votes

You have initialized driver only once and are trying to use the same driver to open and close windows multiple time. Maybe that’s the reason for this reason.

Try this:

for i in range(0,3):
    chromedriver = "F:\omkar\Download\chromedriver"
    driver = webdriver.Chrome(chromedriver)
    url="https://www.edureka.co/community/users?start=" + str(i*200)
    driver.get(url)
    time.sleep(3)
    driver.close()
answered Apr 6, 2019 by James

Related Questions In Python

0 votes
1 answer
0 votes
0 answers
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
8,118 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
7,238 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
4,981 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
6,188 views
0 votes
1 answer

How to create empty pandas dataframe only with column names?

You can do it like this: df=pd.DataFrame(columns=["Name","Old","Ne ...READ MORE

answered Apr 6, 2019 in Python by Hari
7,313 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP