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?

XirrusX
  • 1
  • 1
  • Share your code trials and share the error you are facing. – Shawn Jun 16 '23 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')]"} – XirrusX Jun 16 '23 at 15:05

2 Answers2

1

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

button = driver.find_element(By.XPATH, "//button[contains(text(),'Add Lead')]")
Shawn
  • 4,064
  • 2
  • 11
  • 23
  • For the button, this is the best way to find it via xpath. – Josh Heaps Jun 16 '23 at 14:20
  • 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')]"} – XirrusX Jun 16 '23 at 15:03
  • just read a similar case, does that has something to do with the use of iframe? and what is an iframe? – XirrusX Jun 16 '23 at 15:08
  • Check this answer for switching into IFRAME - https://stackoverflow.com/a/75812495/7598774 – Shawn Jun 16 '23 at 15:49
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

XirrusX
  • 1
  • 1