Selenium Webdriver找不到click按钮的元素

2024-10-03 06:21:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我不知道用来点击按钮的元素。你知道吗

我试着这样写:

driver.find_element_by_xpath('//*/input[@type="button"]').click()

错误消息:

raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementNotVisibleException: Message: element not visible

HTML格式:

<input type="button" name="ctl00$c3$g_6_f947_400a_aa18_59efd84584ae$ctl00$toolBarTbl$RightRptControls$ctl00$ctl00$diidIOSaveItem" value="Save" onclick="if (!PreSaveItem()) return false;if (SPClientForms.ClientFormManager.SubmitClientForm('WPQ2')) return false;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ctl33$g_69_f947_400a_aa18_59efd84584ae$ctl00$toolBarTbl$RightRptControls$ctl00$ctl00$diidIOSaveItem&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, true))" id="ctl00_ctl33_g_696_f947_400a_aa18_59efd84584ae_ct0_toolBarTbl_RightRptControls_ctl00_ctl00_diidIOSaveItem" accesskey="O" class="ms-ButtonHeightWidth" target="_self">

Tags: falseinputreturniftypebuttonelementclass
3条回答

不知道为什么要使用//*/input而不是直接使用//input。这是解决办法。你知道吗

driver.find_element_by_xpath("//input[@type='button' and @value='Save']").click()

你试过寻找价值吗?你知道吗

driver.find_element_by_xpath('//*/input[@value="Save"]').click()

如果这不工作,这将是有益的,如果你可以上传网页的HTML你正在测试或提供的网址。你知道吗

“保存”字是否可见?如果是这样,你可以试试这个:

driver.find_element_by_xpath("//*[contains(text(), 'Save')]").click()

相关问题 更多 >