0

codesample

I am trying to click a button using Firefox - python - webdriver

But every time error comes:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: .pull-right show-toggle with-icon

Am I missing something here? after login and couple of steps I am reaching on one page where I need to click on the button with below class name.

child = driver.find_element_by_class_name('pull-right show-toggle with-icon')
child.click()

Any other way of doing this ?

7
  • Hmm... Actually with your code you should get InvalidSelectorException as search by_class_name doesn't support compound class names... Update your code with original selector. Also check whether your button located inside an iframe Commented Dec 16, 2016 at 8:36
  • Hi Andersson - the button is not under iframe, you can check HTML Page i have added Commented Dec 16, 2016 at 8:42
  • update your code with original selector, what actually this means? Commented Dec 16, 2016 at 8:43
  • It means that driver.find_element_by_class_name('pull-right show-toggle with-icon') should trigger InvalidSelectorException, but not NoSuchElementException... Also there is only little HTML sample on provided image. Are you sure that there is no iframe? Commented Dec 16, 2016 at 8:46
  • Infact i tried parent child relationship as well he is able to find class "Hidden Print" but then also for child it says no class name like this, Commented Dec 16, 2016 at 8:51

1 Answer 1

1

As per provided piece of HTML, you can click your button with following code:

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait as wait

button = wait(driver, 10).until(EC.visibility_of_element_located((By.XPATH,"//a[@data-toggle-text='Hide details']")))
button.click()
Sign up to request clarification or add additional context in comments.

7 Comments

amazing thanks alot it worked finally, but will you be able to give me heads up what xpath is doing here
i got it, its interesting
XPath is more flexible than other approaches to locate element. In this particular XPath you check DOM for ancor with specific attribute (data-toggle-text in this case)
this is working fine for me but problem now is this button will sometimes exist or sometimes not, so when i am running my cude it throws timeout exception because the button is not present how can i build this condition that if you didn't find that button then exit the code
i used pass in place of driver.quit() :)
|

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.