Closed codeIs4Me closed 2 years ago
This is a duplicate of https://github.com/microsoft/pylance-release/issues/2869. It's a bug in older versions of the selenium library. If you upgrade to a recent version (4.2.0), the problem should go away.
yes. couldn't repro on newer version
Had to type this for it to work: pip install selenium==4.2.0 --ignore-installed
Or you could do pip install selenium --upgrade
.
Thank you for your help.
my selenium version is 4.7.2 but this problom happen i think this is same stuation...
but The situation was solved because it was updated to 4.8.0 agian update selenium
I updated selenium in vs code, still its showing the same problem. Help
Generally this problem happens when the type information for one of the methods you're calling indicates it will return Never
. The intent here is to catch an exception statically. Meaning if you call that code with the arguments provided, it will throw an exception.
This particular issue was with the type annotations for selenium. The older version indicated a return of Never
incorrectly, but the newer version fixed that problem.
@Nandinimishra17, it would be better if you opened a new issue. We'd need to have a self contained repro and a list of the packages you have installed.
This works for me with selenium version 4.19.0
omg great it worked! i added a new file w the same code in project folder and it worked.Can you explain the logic behind this?
Generally this problem happens when the type information for one of the methods you're calling indicates it will return
Never
. The intent here is to catch an exception statically. Meaning if you call that code with the arguments provided, it will throw an exception.This particular issue was with the type annotations for selenium. The older version indicated a return of
Never
incorrectly, but the newer version fixed that problem.@Nandinimishra17, it would be better if you opened a new issue. We'd need to have a self contained repro and a list of the packages you have installed.
This works for me with selenium version 4.19.0
Can you explain the logic behind this?
If you're calling a function that we know is going to never return, it means the code after that can't be analyzed.
Suppose there was a function like so:
def foo():
raise Exception("Foo crashes")
And then you called foo in your code.
x = foo()
print(x) # This code is marked as unreachable.
In selenium's case, the function definition for webdriver.Chrome
was marked as throwing an exception.
Environment data
Pylance v2022.6.30
Code Snippet
from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait
opts = webdriver.ChromeOptions() opts.add_experimental_option("detach", True) driver_location = "./chromedriver" driver = webdriver.Chrome(executable_path=driver_location,options=opts) wait = WebDriverWait(driver, 20) driver.get("https://github.com/")
driver.quit()
Repro Steps
If you take out the line "driver = webdriver.Chrome(executable_path=driver_location,options=opts)", then the "wait = WebDriverWait(driver, 20)" will be highlighted correctly and obviously the line after that say issue with driver not being defined.
Expected behavior
Should not grayed out my code thinking it is unreachable.
Actual behavior
My code runs and is fine. But VSCode is wrong in saying that all lines after the "driver = webdriver.Chrome(executable_path=driver_location,options=opts)" are unreachable.
Logs