0

I've tried several ways to locate this element using driver.find_element(By.*) but have had no success. Can anyone provide guidance?

HTML Elements: html elements

<button class="MuiButtonBase-root MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium css-10qa0nr" tabindex="0" type="button">
Add Lead
<span class="MuiTouchRipple-root css-w0pj6f"></span>
</button>

Also, why is the class name so long and should I copy the whole class name or only part of it if I want to locate the element using the class name?

2
  • Share your code trials and share the error you are facing. Commented Jun 16, 2023 at 14:16
  • button = driver.find_element(By.XPATH, "//button[contains(text(),'Add Lead')]") error message: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//button[contains(text(),'Add Lead')]"} Commented Jun 16, 2023 at 15:05

2 Answers 2

1

You can use XPath locator and it's contains method like below:

button = driver.find_element(By.XPATH, "//button[contains(text(),'Add Lead')]")
Sign up to request clarification or add additional context in comments.

4 Comments

For the button, this is the best way to find it via xpath.
button = driver.find_element(By.XPATH, "//button[contains(text(),'Add Lead')]") tried this solution and get this error message: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//button[contains(text(),'Add Lead')]"}
just read a similar case, does that has something to do with the use of iframe? and what is an iframe?
Check this answer for switching into IFRAME - stackoverflow.com/a/75812495/7598774
0

Found the solution:

Need to switch the driver to iframe first before locating the element.

When inspecting the element, need to scroll up to see if the element is inside the iframe or not

inspect element selenium script

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.