Home > Enterprise >  Can't use Selenium Python to click on a button
Can't use Selenium Python to click on a button

Time:05-26

I'm pretty new to Selenium and I was trying to create a script to automate some stuff. I can't click on this one button with selenium. This is what I was trying to do, and I have tried a bunch of other options as well. driver.find_element_by_css_selector('a.n_mmi').click() This is the element I am trying to select. the element

What is the proper way to do this?

CodePudding user response:

It looks like you misread the id, it's actually m_mmi.
Also as the error says and Effi Hol already pointed out. The find_element_by_* functions are deprecated and you should use findElement() instead.

This should work for you:

driver.findElement(By.id('m_mmi')).click()

CodePudding user response:

Pay attention that n_mmi is the Id and not the class of the element, So change the code as follows:

driver.driver.findElement(By.cssSelector('#n_mmi')).click()

Also, according to the picture you added in the comment, it says that find_element_by_css is deprecated.

CodePudding user response:

The Selenium website has an always helpful example of useage whenever you need a refresher on it's API's https://selenium-python.readthedocs.io/getting-started.html

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
  • Related