[英]Using selenium to click a button
For clicking a button with the following HTML code:单击具有以下 HTML 代码的按钮:
<a href="javascript:submitPage('V','All Notes','');" class="viewFilter">All Notes</a>
I have tried multiple ways to click/ access this button but to no success, for example:我尝试了多种方法来单击/访问此按钮,但均未成功,例如:
all_notes = wait.until(EC.presence_of_element_located((By.XPATH, "//a[@href='javascript:submitPage('V','All Notes','');']"))).click()
all_notes = wait.until(EC.presence_of_element_located((By.XPATH, "//href[@type='class' and @value='View All']"))).click()
I am not really sure what the issue is here - for all other button presses on this webpage - selenium has been working appropriately.我不确定这里的问题是什么 - 对于此网页上的所有其他按钮按下 - selenium 一直在正常工作。 What other ways can I try?
我还可以尝试哪些其他方法?
all_notes = WebDriverWait(driver,10).until(EC.presence_of_element_located(
(By.XPATH, '//*[@href="javascript:submitPage(\'V\',\'All Notes\',\'\');"]'))).click()
escape the single quotes转义单引号
Try this Xpath...试试这个 Xpath...
//a[@class='viewFilter' and contains(text(), 'All Notes')]
What this does is verifies that the class is viewFilter and since classes can appear more than once also ensure that the link text is All Notes.这样做是为了验证 class 是 viewFilter 并且由于类可以出现多次,因此也确保链接文本是所有注释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.