简体   繁体   English

单击 Selenium 中的按钮元素

[英]Click button element in Selenium

HTML code for the button I want to click我要单击的按钮的 HTML 代码

Can anyone please help me, I'm trying to tell selenium to click a button on a website I'm trying to automate.谁能帮帮我,我正试图告诉 selenium 点击我试图自动化的网站上的按钮。 Ive attached a picture of the HTMl code that I want the Webdriver to click.我附上了一张我希望 Webdriver 点击的 HTMl 代码的图片。 Can anyone tell me the best find element option to use to click the button.谁能告诉我用于单击按钮的最佳查找元素选项。 Ive looked into Xpath but can't seem to get it working?我查看了 Xpath 但似乎无法正常工作? Thanks谢谢

<use xlink:href="#icon-menu-more" href="#icon-menu-more"></use>

So I was trying to grab the xPath from this line of code.所以我试图从这行代码中获取 xPath。 the Xpath is /html/body/div/div[1]/header/nav/button[1]/span[1]/svg/use but then when trying to use driver.find_element_by_xpath() i get an error saying unable to locate element. Xpath 是/html/body/div/div[1]/header/nav/button[1]/span[1]/svg/use但是当尝试使用driver.find_element_by_xpath()我得到一个错误,说无法定位元素。

You can try你可以试试

driver.find_element_by_id('icon-menu-more')

this will help you to click the button这将帮助您单击按钮

Other Options are其他选项是

driver.find_element_by_name('name of element')
driver.find_element_by_class_name('class name of element')
driver.find_element_by_tag_name(tag name of element)
driver.find_element_by_css_selector('css selector of element')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM