如何在python selenium中使用style属性查找webelement

迪维亚玛尼

我想根据样式和类名给 Click 按钮,因为在我的情况下没有唯一的类名和 id。

我的 html 代码是

<a class="x-btn x-unselectable rp-important-btn rp-btn-shadow x-box-item x-toolbar-item x-btn-default-small x-noicon x-btn-noicon x-btn-default-small-noicon" 
style="height: 24px; right: auto; top: 5px; margin: 0px; left: 118px;" hidefocus="on" unselectable="on" tabindex="0">

我试过

 save_class=driver.find_element_by_xpath("//a[@class='x-btn x-unselectable rp-important-btn rp-btn-shadow x-box-item x-toolbar-item x-btn-default-small x-noicon x-btn-noicon x-btn-default-small-noicon' 
 and style='height: 24px; right: auto; top: 5px; margin: 0px; left: 118px;']")

我收到以下错误:

selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素:{"method":"xpath","selector":"//a[@class='x-btn x-unselectable rp-important -btn rp-btn-shadow x-box-item x-toolbar-item x-btn-default-small x-noicon x-btn-noicon x-btn-default-small-noicon' and style='height: 24px;右:自动;顶部:5px;边距:0px;左:118px;']"}

帕克斯

你忘记@style了你的 xpath

save_class=driver.find_element_by_xpath("//a[@class='x-btn x-unselectable rp-important-btn rp-btn-shadow x-box-item x-toolbar-item x-btn-default-small x-noicon x-btn-noicon x-btn-default-small-noicon' and @style='height: 24px; right: auto; top: 5px; margin: 0px; left: 118px;']")

试试这个!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Python中使用Selenium Webdriver提取Webelement

如何使用具有相同属性的 Selenium 查找多个不同的 Webelement?

如何在python中使用selenium查找搜索區域

如何在 selenium Python 中使用 onclick 查找元素?

如何在Selenium和Python中使用类型查找元素

如何在Python中使用Selenium?

如何在Selenium Python中使用JavaScript

如何在python中导入Selenium WebElement

如何在Python中使用Exception的属性?

如何使用Selenium Webdriver测试WebElement属性是否存在

如何在Selenium WebDriver的属性文件中使用多行属性?

如何使用 Selenium 查找 HTML <style> 标签

如何在jupyterhub页面中使用python-selenium查找现有的HTML元素?

如何在Selenium Webdriver中使用WebElement获取节点h2的HTML Source?

如何在bokeh文档中使用Selenium WebDriver查找按钮?

如何使用Selenium检索WebElement的文本-Python

如何在Selenium WebDriver中使用JavascriptExecuter设置属性值

如何在Python中使用Pandas查找精度@ N

我如何在python中使用nltk查找特定的bigram?

如何在Python中使用O(1)查找列表元素?

如何在 Python 中使用 BeautifulSoup 查找特定的 HTML 元素

如何在 Python 中使用 Webbot 加快查找文本的速度

如何在 Python Selenium 中使用 css 或运算符

如何在python-selenium中使用browsermob?

如何在 FireFox 中使用 Python Selenium 放大网页

如何在selenium python中使用索引号访问xpath?

如何在Python中使用Selenium Webdriver提取文本?

如何在Python中使用Selenium访问弹出表单

如何在python中使用Selenium和Beautifulsoup解析网站?