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 5 in Python by Raj
174 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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 5 by James

Related Questions In Python

+3 votes
5 answers

How to read multiple data files in python

Firstly we will import pandas to read ...READ MORE

answered Apr 6, 2018 in Python by DeepCoder786
• 1,700 points
524 views
+1 vote
1 answer

How to replace id with attribute corresponding to id of another table?

Use the following query statement and let ...READ MORE

answered Aug 8, 2018 in Python by Priyaj
• 56,120 points
14 views
0 votes
1 answer

How to add to the python path in Windows?

You know what has worked for me ...READ MORE

answered Jul 25, 2018 in Python by Frankie
• 9,590 points
38 views
0 votes
1 answer

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,030 points
71 views
0 votes
1 answer
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,130 points
443 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
55 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","New ...READ MORE

answered Apr 5 in Python by Hari
41 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.