Hi guys i am new on selenium i tried to search from website's textbox
There is my code:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
PATH="C:\Program Files (x86)\chromedriver.exe"
s=Service(PATH)
driver = webdriver.Chrome(service=s)
url='https://www.techwithtim.net/'
driver.get(url)
print(driver.title)
search=driver.find_element(by=By.NAME, value="s")
search.send_keys("test")
search.send_keys(Keys.ENTER)
time.sleep(5)
driver.close() #driver
The program is able to search, but it throws an error at the search.send_keys(Keys.ENTER) line and exits the code.
I can't give all error for you because of this website doesn't allow i don't know
so some of the error:
File "C:/Users/User/PycharmProjects/us1/selen.py", line 16, in <module>
search.send_keys(Keys.ENTER)
File "C:\Users\User\PycharmProjects\us1\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 223, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT,
File "C:\Users\User\PycharmProjects\us1\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 396, in _execute
return self._parent.execute(command, params)
File "C:\Users\User\PycharmProjects\us1\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 435, in execute
self.error_handler.check_response(response)
File "C:\Users\User\PycharmProjects\us1\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot determine loading status
from unknown error: unexpected command response
(Session info: chrome=103.0.5060.66)
Stacktrace:
Backtrace:
Ordinal0 [0x00F36463 2188387]
Ordinal0 [0x00ECE461 1762401]
Ordinal0 [0x00DE3D78 802168]
Ordinal0 [0x00DD7210 750096]
.
.
.
CodePudding user response:
You have to download chrome driver exe from below path as per installed chrome version and use the respective chrome driver. Selenium works on chromedriver.exe. You have to download the chrome driver exe and paste it in your computer and in path you have to give location of the chrome driver exe.
https://chromedriver.chromium.org/downloads
driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe")
driver.get("https://www.techwithtim.net/")
CodePudding user response:
So I faced the same error on my desktop, turns out that this has something to do with version mismatch.
My chrome version was
Version 103.0.5060.66 (Official Build) (64-bit)
So I updated my chrome driver to version
103.0.5060.53
You can try updating your chrome and chrome driver accordingly.
If you are using Chrome version
104
, please download ChromeDriver104.0.5112.20
If you are using Chrome version
103
, please download ChromeDriver103.0.5060.53
If you are using Chrome version
102
, please download ChromeDriver102.0.5005.61
You can check your chrome version here chrome://settings/help
Once updated, the below code should work fine
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
chrome_path = r"C:\Users\hpoddar\Desktop\Tools\chromedriver_win32\chromedriver.exe"
s = Service(chrome_path)
url = 'https://www.techwithtim.net/'
driver = webdriver.Chrome(service=s)
driver.get(url)
time.sleep(5)
driver.maximize_window()
search=driver.find_element(by=By.CLASS_NAME, value="search-field")