2

I am trying to create a Python program that periodically checks a website for a specific update. The site is secured and multiple clicks are required to get to the page that I want to monitor. Unfortunately, I am stuck trying to figure out how to click a specific button. Here is the button code:

<input type="button" class="bluebutton" name="manageAptm" value="Manage Interview Appointment" onclick="javascript:programAction('existingApplication', '0');">

I have tried numerous ways to access the button and always get "selenium.common.exceptions.NoSuchElementException:" error. The obvious approach to access the button is XPath and using the Chrome X-Path Helper tool, I get the following:

/html/body/form/table[@class='appgridbg mainContent']/tbody/tr/td[2]/div[@class='maincontainer']/div[@class='appcontent'][1]/table[@class='colorgrid']/tbody/tr[@class='gridItem']/td[6]/input[@class='bluebutton']

If I include the above as follows:

browser.find_element_by_xpath("/html/body/form/table[@class='appgridbg mainContent']/tbody/tr/td[2]/div[@class='maincontainer']/div[@class='appcontent'][1]/table[@class='colorgrid']/tbody/tr[@class='gridItem']/td[6]/input[@class='bluebutton']").submit()

I still get the NoSuchElementException error.

I am new to selenium and so there could be something obvious that I am missing; however, after much Googling, I have not found an obvious solution.

On another note, I have also tried find_element_by_name('manageAptm') and find_element_by_class_name('bluebutton') and both give the same error.

Can someone advise on how I can effectively click this button with Selenium?

Thank you!

1
  • The find_element_by_name you tried looks promising to me. Try to use it with wait Commented Apr 29, 2016 at 2:09

1 Answer 1

1

To follow your attempts and the @har07's comment, the find_element_by_name('manageAptm') should work, but the element might not be immediately available and you may need to wait for it:

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

wait = WebDriverWait(driver, 10)
manageAppointment = wait.until(EC.presence_of_element_located((By.NAME, "manageAptm")))
manageAppointment.click()

Also, check if the element is inside an iframe or not. If yes, you would need to switch into the context of it and only then issue the "find" command:

driver.switch_to.frame("frame_name_or_id")
driver.find_element_by_name('manageAptm').click()
Sign up to request clarification or add additional context in comments.

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.