python - 'str' 对象在使用按类查找元素时不可调用 | 蟒蛇硒
问题描述
当我正在编写以下代码时,无法单击按钮。它显示错误“TypeError:'str'对象不可调用”
代码
shopping_btn = self.driver.find_element(By.CLASS_NAME("cta cta-hover-animate cta-fill-black-outline-black"))
shopping_btn.click()
错误:
文件“E:\Python\setests\smoketest.py”,第 33 行,在 test_shopping_cart_empty_message shopping_btn = self.driver.find_element(By.CLASS_NAME("cta cta-hover-animate cta-fill-black-outline-black")) TypeError:“str”对象不可调用
解决方案
你需要像这样使用 find_element :
shopping_btn = self.driver.find_element(By.CLASS_NAME, "cta cta-hover-animate cta-fill-black-outline-black")
shopping_btn.click()
由于尝试调用而出现异常
By.CLASS_NAME('<your_selector>')
什么是平等的
"any_string"('<you_selector>')
推荐阅读
- javascript - 网站启动时立即运行 iframe
- html - 为什么当我使用 svg 线时,我的 div 附近会出现一个未识别的段?
- javascript - 如何在另一个调用 this.setState() 的函数内部的函数中访问组件的状态?
- oauth-2.0 - 无头桌面客户端 Web 服务客户端应该是动态注册的 OIDC 客户端 - 还是其他?
- excel - excel 2013中的过期公式
- c - c struct size with void * value members
- aws-appsync - 检查 AWS Appsync 是否连接到端点套接字
- python - 我怎样才能漂亮地打印一个 nltk 树对象?
- gcc - GCC 是否有充分的理由生成跳转以跳过一条廉价指令?
- json - 在 Kotlin 中使用可变列表持久化 JSON