SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.64k stars 8.18k forks source link

[🐛 Bug]selenium.common.exceptions.WebDriverException: Message: no such execution context: #13612

Closed virt12 closed 8 months ago

virt12 commented 8 months ago

What happened?

I have tried to reach website url: stock_list =[

        {"url": "https://www.nasdaqomxnordic.com/shares/microsite?Instrument=HEX185076", "csv_name": f"{p}/FARON.csv","ISIN":"FI4000153309"}

           driver.get(url)

] After this code crashes and getting an errror: selenium.common.exceptions.WebDriverException: Message: no such execution context

How can we reproduce the issue?

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import csv
import time
import glob
import os
import pandas as pd
import re, os.path
import operator
from pathlib import Path
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
import numpy as np
from selenium.webdriver.edge.options import Options

#from msedge.selenium_tools import EdgeOptions
#from msedge.selenium_tools import Edge
from selenium.webdriver.common.by import By

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException

from selenium.webdriver.common.action_chains import ActionChains
import traceback

p="C:/Users/apskaita3/Finansų analizės ir valdymo sprendimai, UAB/Rokas Toomsalu - Power BI analitika/Integracijos/1_Public comapnies analytics/Databasesets/Nasdaq_tradings_Helsinki"

stock_list =[

            {"url": "https://www.nasdaqomxnordic.com/shares/microsite?Instrument=HEX185076", "csv_name": f"{p}/FARON.csv","ISIN":"FI4000153309"}

]
b=len(stock_list)
ind=0 
delay = 5

for i in stock_list:
    ind+=1
    csv_name = i['csv_name']
    url = i['url']
    print(csv_name)

    #driver = webdriver.Edge(r"C:/Users/apskaita3/Desktop/msedgedriver.exe")

    #driver=webdriver.Firefox(executable_path=r'C:\Users\apskaita3\Desktop\gec\geckodriver.exe',service_log_path=os.devnull)
    time.sleep(1)
    driver = webdriver.Edge()
    #driver = webdriver.Edge(r"C:/Users/apskaita3/Desktop/msedgedriver.exe")

    #driver = webdriver.Chrome(executable_path=r"C:\path\to\chromedriver.exe")

    #driver.refresh()
    #driver.minimize_window()
    driver.get(url)
    print(url)
    time.sleep(2)

    driver.execute_script("window.scrollTo(1328, 917)")
    #driver.implicitly_wait(5)
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, 'cookieConsentOK')))

    # Handle cookie consent
    cookie_consent_button = driver.find_element(By.ID, 'cookieConsentOK')
    cookie_consent_button.click()

    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID, "exportIntradayTradesCSV"))
    )
    #driver.find_element_by_class_name('displayBlock').click()
# Now that the element is present, perform your desired action
    element.click()  
    #element = driver.find_element_by_id("exportIntradayTradesCSV")
    #element = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.ID, 'exportIntradayTradesCSV')))
    #element = driver.find_element(By.ID, 'exportIntradayTradesCSV')
    #ActionChains(driver).move_to_element(element).click().perform()

    #com = WebDriverWait(driver,25).until(EC.visibility_of_element_located( (By.ID, 'exportIntradayTradesCSV') )).click()

    #com.click()

    print('driver')
    #time.sleep(10)
    time.sleep(7)
    #driver.refresh()

    #driver.stop_client()
    #driver.close()
    driver.quit()
    #driver.close()

    accepted_extensions = ["csv","crdownload"]
    filenames = [fn for fn in os.listdir("C:/Users/apskaita3/Downloads/") if fn.split(".")[-1] in accepted_extensions]

    filenames = [s for s in filenames if "share_export" in s]
    print(filenames)

    time.sleep(5)
    #a1=filenames[0]

    try:
        a1=filenames[0]
    except IndexError:
        traceback_str = traceback.format_exc()
        with open("C:/Users/apskaita3/Documents/log_helsinki.txt", "w") as error_file:
            error_file.write(traceback_str)
        continue

        #continue
    #a1=filenames[0]

    try:
      old_csv = pd.read_csv(f'C:/Users/apskaita3/Downloads/{a1}',sep=';',skiprows=1)
    except pd.errors.EmptyDataError:
      old_csv  = pd.DataFrame(columns=['Execution Time', 'Execution Time UTC', 'ISIN', 'Publication Time','Publication Time UTC','CCY','Venue of execution (MIC Code)', 'Venue of publication (MIC Code)','Price notation','Transaction to be cleared','MMT Flags','Transaction ID Code', 'Price', 'Volume', 'Buyer', 'Seller', 'Trade type'])

    time.sleep(1)
    new_csv = pd.read_csv(csv_name,sep=';')
    if ('sep='  in new_csv.columns.tolist()):
        new_csv = pd.read_csv(csv_name,sep=';',skiprows=1)

    else:
       new_csv = pd.read_csv(csv_name,sep=',')

    new_df = pd.concat([old_csv, new_csv]).reset_index(drop=True)

    #new_df.columns = old_csv.columns

    try:
        new_df.columns = old_csv.columns
    except ValueError:
        os.chdir("C:/Users/apskaita3/Downloads")
        for e in os.listdir():
            if "share_export" in e:
                os.remove(e)
            else:
                pass
       # continue

    #new_df=new_df.sort_values(['Execution Time', 'Transaction ID Code'],ascending = [False, False])

    #new_df = new_df[new_df["ISIN"] == i['ISIN']]
    #new_df = new_df[new_df["ISIN"] == old_csv['ISIN'].iloc[0]]

    new_df = new_df[new_df["ISIN"] == i['ISIN']]
    """
    try:
        #new_df = new_df[new_df["ISIN"] == old_csv['ISIN'].iloc[0]]
        new_df = new_df[new_df["ISIN"] == i['ISIN']] 
    except IndexError:
         os.chdir("C:/Users/apskaita3/Downloads")
         for e in os.listdir():
            if "share_export" in e:
                os.remove(e)
            else:
                pass
         continue
    """
    #new_df["ISIN"]=new_df["ISIN"].drop_duplicates(keep='first')
    #new_df["ISIN"] = i['ISIN']
    new_df.to_csv(csv_name,index = False)
    new_csvx= pd.read_csv(csv_name,sep=',')
    new_csvx['Transaction ID Code'] = new_csvx['Transaction ID Code'].astype(str).str.lstrip('0')
    #new_csvx['Execution Time'] = new_csvx['Execution Time'].astype(str).str.rstrip(':00')
    #new_csvx['Publication Time'] = new_csvx['Publication Time'].astype(str).str.rstrip(':00')

    new_csvx=new_csvx.sort_values(['Publication Time', 'Transaction ID Code'],ascending = [False, False]).drop_duplicates()
    new_csvx.to_csv(csv_name,index = False)

    os.chdir("C:/Users/apskaita3/Downloads")
    for e in os.listdir():
      if "share_export" in e:
        os.remove(e)
      else:
        pass

    with open('C:/Users/apskaita3/Documents/vars.txt', 'w') as f:
            f.write(str(ind))
            f.write(',')
            f.write(str(b))

    filenames.clear()

    time.sleep(6)

Relevant log output

Traceback (most recent call last):
  File "C:\Users\apskaita3\helsinki_tradings_edge.py", line 446, in <module>
    driver.get(url)
  File "C:\Users\apskaita3\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\remote\webdriver.py", line 356, in get
    self.execute(Command.GET, {"url": url})
  File "C:\Users\apskaita3\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\remote\webdriver.py", line 347, in execute
    self.error_handler.check_response(response)
  File "C:\Users\apskaita3\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\remote\errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: no such execution context
  (Session info: MicrosoftEdge=121.0.2277.128)
Stacktrace:
        GetHandleVerifier [0x00007FF6D481B892+60738]
        Microsoft::Applications::Events::ILogConfiguration::operator* [0x00007FF6D47A7B32+233090]
        (No symbol) [0x00007FF6D45BAC43]
        (No symbol) [0x00007FF6D45A4390]
        (No symbol) [0x00007FF6D45A1D0D]
        (No symbol) [0x00007FF6D45A2BAF]
        (No symbol) [0x00007FF6D45B160D]
        (No symbol) [0x00007FF6D45C75F3]
        (No symbol) [0x00007FF6D45CC89A]
        (No symbol) [0x00007FF6D45A35F4]
        (No symbol) [0x00007FF6D45A3230]
        (No symbol) [0x00007FF6D45C71AB]
        (No symbol) [0x00007FF6D4649438]
        (No symbol) [0x00007FF6D462C233]
        (No symbol) [0x00007FF6D45FD568]
        (No symbol) [0x00007FF6D45FC394]
        (No symbol) [0x00007FF6D45FD101]
        Microsoft::Applications::Events::EventProperty::to_string [0x00007FF6D49D7D2C+1072924]
        (No symbol) [0x00007FF6D4680F45]
        (No symbol) [0x00007FF6D4718F6C]
        (No symbol) [0x00007FF6D4710A5D]
        Microsoft::Applications::Events::EventProperty::to_string [0x00007FF6D49D6773+1067363]
        Microsoft::Applications::Events::ILogConfiguration::operator* [0x00007FF6D47B1A88+273880]
        Microsoft::Applications::Events::ILogConfiguration::operator* [0x00007FF6D47AC794+252644]
        Microsoft::Applications::Events::ILogConfiguration::operator* [0x00007FF6D47AC8C2+252946]
        Microsoft::Applications::Events::ILogConfiguration::operator* [0x00007FF6D47A2EC1+213521]
        BaseThreadInitThunk [0x00007FF82177257D+29]
        RtlUserThreadStart [0x00007FF82396AA58+40]

Press any key to continue . . .

Operating System

Windows 11

Selenium version

4.15.2

What are the browser(s) and version(s) where you see this issue?

Microsoft Edge

What are the browser driver(s) and version(s) where you see this issue?

Microsoft Edge 121.0.2277.128 Stable Channel

Are you using Selenium Grid?

No response

github-actions[bot] commented 8 months ago

@virt12, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

diemol commented 8 months ago

Can you provide a minimized set of code lines that reproduce the issue? The code you pasted has several lines commented and seems to have external dependencies.

virt12 commented 8 months ago

Yes I can. The error comes after this line, so part of code:

`from selenium import webdriver from selenium.webdriver.common.keys import Keys import csv import time import glob import os import pandas as pd import re, os.path import operator from pathlib import Path from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service import numpy as np from selenium.webdriver.edge.options import Options

from msedge.selenium_tools import EdgeOptions

from msedge.selenium_tools import Edge

from selenium.webdriver.common.by import By

from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium.common.exceptions import TimeoutException

from selenium.webdriver.common.action_chains import ActionChains import traceback

p="C:/Users/apskaita3/Finansų analizės ir valdymo sprendimai, UAB/Rokas Toomsalu - Power BI analitika/Integracijos/1_Public comapnies analytics/Databasesets/Nasdaq_tradings_Helsinki"

stock_list =[ {"url": "https://www.nasdaqomxnordic.com/shares/microsite?Instrument=HEX185076", "csv_name": f"{p}/FARON.csv","ISIN":"FI4000153309"}

] b=len(stock_list) ind=0 delay = 5

for i in stock_list: ind+=1 csv_name = i['csv_name'] url = i['url'] print(csv_name)

driver = webdriver.Edge()

driver.get(url)`
diemol commented 8 months ago

You still have external dependencies:

p="C:/Users/apskaita3/Finansų analizės ir valdymo sprendimai, UAB/Rokas Toomsalu - Power BI analitika/Integracijos/1_Public comapnies analytics/Databasesets/Nasdaq_tradings_Helsinki"

Can you provide a code snippet that works without external dependencies? Only Selenium?

Are you able to reproduce the issue in Firefox and Chrome?

virt12 commented 8 months ago

Can you provide a minimized set of code lines that reproduce the issue? The code you pasted has several lines commented and seems to have external dependencies.

`from selenium import webdriver from selenium.webdriver.common.keys import Keys import csv import time import glob import os import pandas as pd import re, os.path import operator from pathlib import Path from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service import numpy as np from selenium.webdriver.edge.options import Options

from msedge.selenium_tools import EdgeOptions

from msedge.selenium_tools import Edge

from selenium.webdriver.common.by import By

from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium.common.exceptions import TimeoutException

from selenium.webdriver.common.action_chains import ActionChains import traceback

stock_list =[

        {"url": "https://www.nasdaqomxnordic.com/shares/microsite?Instrument=HEX185076", "csv_name": f"C:Desltp[/FARON.csv","ISIN":"FI4000153309"}

] b=len(stock_list) ind=0 delay = 5

for i in stock_list: ind+=1 csv_name = i['csv_name'] url = i['url'] print(csv_name)

time.sleep(1)
driver = webdriver.Edge()

driver.get(url)`
diemol commented 8 months ago

Sorry, this still has several external dependencies and a CSV file. We cannot triage this.

github-actions[bot] commented 8 months ago

Hi, @virt12. Please follow the issue template, we need more information to reproduce the issue.

Either a complete code snippet and URL/HTML (if more than one file is needed, provide a GitHub repo and instructions to run the code), the specific versions used, or a more detailed description to help us understand the issue.

Note: If you cannot share your code and URL/HTML, any complete code snippet and URL/HTML that reproduces the issue is good enough.

Reply to this issue when all information is provided, thank you.

diemol commented 8 months ago

I recommend trying with Firefox or Chrome before adding more information to this issue.

virt12 commented 8 months ago

I recommend trying with Firefox or Chrome before adding more information to this issue.

Ok, without dependencies.

`from selenium import webdriver from selenium.webdriver.common.keys import Keys import csv import time import glob import os import pandas as pd import re, os.path import operator from pathlib import Path from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service import numpy as np from selenium.webdriver.edge.options import Options

from msedge.selenium_tools import EdgeOptions

from msedge.selenium_tools import Edge

from selenium.webdriver.common.by import By

from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium.common.exceptions import TimeoutException

from selenium.webdriver.common.action_chains import ActionChains import traceback

stock_list =[

        {"url": "https://www.nasdaqomxnordic.com/shares/microsite?Instrument=HEX185076"}

] b=len(stock_list) ind=0 delay = 5

for i in stock_list: ind+=1

url = i['url']

time.sleep(1)
driver = webdriver.Edge()

driver.get(url)`

Actually I have tried to use Chrome and Firefox and Edge seemed more reliable.

virt12 commented 8 months ago

Another observation, that code crashed after 20 runnings, error appears randomly not each time while running code. Recently, I have updated webdriver, browser ant Selenium itself. Is it webdriver bug itself?

virt12 commented 8 months ago

I recommend trying with Firefox or Chrome before adding more information to this issue

I have tried already.

diemol commented 8 months ago

I think I've seen that error in Chrome, so it makes sense to see it in Edge.

The issue is that you are not providing code that can be easily used to reproduce the issue, which the Edge or Chrome folks will require to even have a look at.

virt12 commented 8 months ago

I think I've seen that error in Chrome, so it makes sense to see it in Edge.

The issue is that you are not providing code that can be easily used to reproduce the issue, which the Edge or Chrome folks will require to even have a look at.

Could you refer to it, where you saw it in chrome case?

diemol commented 8 months ago

I thought you had already searched in the existing closed issues for "no such execution context". You should find something there.

virt12 commented 8 months ago

I thought you had already searched in the existing closed issues for "no such execution context". You should find something there.

It seems webdriver bug?

diemol commented 8 months ago

Issue #13543 shows the same error. I will share the ChromeDriver link so you can report it over there.

github-actions[bot] commented 8 months ago

Hi, @virt12. This issue has been determined to require fixes in ChromeDriver.

You can see if the feature is passing in the Web Platform Tests.

If it is something new, please create an issue with the ChromeDriver team. Feel free to comment the issues that you raise back in this issue. Thank you.

virt12 commented 8 months ago

Issue #13543 shows the same error. I will share the ChromeDriver link so you can report it over there.

So I need move to firefox?

github-actions[bot] commented 7 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.