Home > other >  How to click google first link selenium
How to click google first link selenium

Time:10-05

I am trying to visit the first link using this code but it does not work, why?

from gettext import find
from tkinter import Button
from xml.dom.minidom import Element
import selenium
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys

kaupunki = "Helsinki"

PATH= "C:\Program Files (x86)\selenium\chromedriver.exe"
driver= webdriver.Chrome(PATH)

driver.get("https://www.google.com")

accept = driver.find_element("xpath" , '//*[@id="L2AGLb"]/div')
time.sleep(2)
accept.click()

searching = driver.find_element("name", 'q')

searching.send_keys("airbnb ",kaupunki)
time.sleep(0.2)

searching.send_keys(Keys.ENTER)
time.sleep(2)

driver.find_element("tag name", "h3").click()```

Output is

c:\Users\sachi\seleniummm.py:13: DeprecationWarning: executable_path has been deprecated,


how can I fix this and get this working? I have checked other posts but it tells me to do the same. But I am not sure why this is not working.
 

CodePudding user response:

Path is now deprecated, so that Service is used instead.
So, instead of

PATH= "C:\Program Files (x86)\selenium\chromedriver.exe"
driver= webdriver.Chrome(PATH)

Try the following:

from selenium.webdriver.chrome.service import Service

webdriver_service = Service('C:\Program Files (x86)\selenium\chromedriver.exe')
driver = webdriver.Chrome(service=webdriver_service)

CodePudding user response:

You have to use Service:

from selenium.webdriver.chrome.service import Service

PATH= "C:\Program Files (x86)\selenium\chromedriver.exe"
driver= webdriver.Chrome(service=Service(PATH))
  • Related