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
675 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 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
1,019 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,160 points
20 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,810 points
61 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,050 points
258 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
624 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
250 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
65 views