3

I'm trying to execute a selenium program in Python to go to a new URL on click of a button in the current homepage. I'm new to selenium and any help regarding this would be appreciated. Here's my code

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

url = 'https://nmit.ac.in'

driver = webdriver.Chrome()

driver.get(url)

try:
    # wait 10 seconds before looking for element
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located(By.LINK_TEXT, "Parent Portal")
    )

except:
    print()

driver.find_element(By.LINK_TEXT, "Parent Portal").click()

I have tried to increase the wait time as well as using all forms of the supported located strategies under the BY keyword, but to no avail. I keep getting this error. Error photo

KrevoL
  • 103
  • 1
  • 1
  • 7

3 Answers3

3

A lot of time passed while I was looking for a solution and I found it here.

options = webdriver.ChromeOptions()

options.add_experimental_option('excludeSwitches', ['enable-logging'])

driver = webdriver.Chrome(
    service= Service(chromedriver_path), 
    options=options,
)

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

It should remove all annoying errors and warnings from selenium

Eugene
  • 43
  • 5
2

As far as I know, you shouldn't be worried by those errors. Although, I proved your code and it's not finding any element in the web page. I can recommend you use the xpath of the element you want to find:

    # wait 10 seconds before looking for element
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.XPATH, "/html//div[@class='wsmenucontainer']//button[@href='https://nmitparents.contineo.in/']"))
    )   
    element.click()
    #wait for the new view to be loaded
    time.sleep(10)  
    driver.quit()

Psdt: you can use the extention Ranorex Selocity to extract a good and unique xpath of any element in a webpage and also test it!! image

  • It's working for me when I ignored those errors like you said, seemingly it just takes time for the website to respond to the click or for selenium to click. – KrevoL Jan 22 '23 at 12:26
0

I was able to get around it using:

options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
greybeard
  • 2,249
  • 8
  • 30
  • 66