0

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?

2
  • 1
    find_element_by_id instead, driver.find_element_by_id('n_mmi').click() Commented May 25, 2022 at 20:40
  • Didn't work unfortunately. Got this error: imgur.com/a/vmeMcDN Commented May 25, 2022 at 21:05

3 Answers 3

1

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()
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

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()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.