Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Selenium和Python 2.7单击表单中的按钮?_Python_Python 2.7_Selenium_Xpath_Selenium Webdriver - Fatal编程技术网

如何使用Selenium和Python 2.7单击表单中的按钮?

如何使用Selenium和Python 2.7单击表单中的按钮?,python,python-2.7,selenium,xpath,selenium-webdriver,Python,Python 2.7,Selenium,Xpath,Selenium Webdriver,我试图创建一个Python程序,定期检查网站的特定更新。该网站是安全的,需要多次点击才能进入我想要监控的页面。不幸的是,我一直在想如何点击一个特定的按钮。以下是按钮代码: <input type="button" class="bluebutton" name="manageAptm" value="Manage Interview Appointment" onclick="javascript:programAction('existingApplication', '0');">

我试图创建一个Python程序,定期检查网站的特定更新。该网站是安全的,需要多次点击才能进入我想要监控的页面。不幸的是,我一直在想如何点击一个特定的按钮。以下是按钮代码:

<input type="button" class="bluebutton" name="manageAptm" value="Manage Interview Appointment" onclick="javascript:programAction('existingApplication', '0');">
如果我将上述内容包括在内,如下所示:

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()
我仍然得到NoTouchElementException错误

我是硒的新手,因此可能有一些明显的东西我遗漏了;然而,在谷歌搜索了很多之后,我还没有找到一个明显的解决方案

另一方面,我还尝试了按名称(“manageAptm”)查找元素和按类名称(“bluebutton”)查找元素,但都给出了相同的错误

有人能告诉我如何用Selenium有效地点击这个按钮吗


谢谢大家!

要跟踪您的尝试和@har07的评论,
find_element_by_name('manageAptm')
应该可以工作,但该元素可能不会立即可用,您可能需要:

此外,检查元素是否位于
iframe
内。如果是,则需要切换到它的上下文,然后才发出“find”命令:


您尝试的按名称查找元素对我来说很有希望。试着和你的朋友一起使用它
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()
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()
driver.switch_to.frame("frame_name_or_id")
driver.find_element_by_name('manageAptm').click()