当前位置:网站首页>已解决(最新版selenium框架元素定位报错)NameError: name ‘By‘ is not defined
已解决(最新版selenium框架元素定位报错)NameError: name ‘By‘ is not defined
2022-07-31 03:50:00 【无 羡ღ】
已解决(最新版selenium框架元素定位报错)NameError: name ‘By‘ is not defined
报错代码
一个粉丝群的小伙伴提出的问题,操作selenium定位元素的时候报错:

报错代码:

报错信息:NameError: name ‘By‘ is not defined
报错翻译
报错内容翻译:
名称报错:未定义名称 “By”
报错原因
报错原因:selenium框架元素定位的最新语法是需要在导入By模块的,而他复制没有的代码没有导入
解决方法
在开头导入By模块:
from selenium.webdriver.common.by import By
完整代码:
from selenium.webdriver.common.by import By
# 获取第一个元素
browser.find_element(by=By.CLASS_NAME, value="element")
# 获取多个元素
browser.find_elements(by=By.CLASS_NAME, value="element")
边栏推荐
- Daily practice of LeetCode - 138. Copy a linked list with random pointers
- Difference between unallocated blocks and unused blocks in database files
- IDEA common shortcut keys and plug-ins
- A brief introduction to the CheckBox component of the basic components of Flutter
- Redis 使用 sorted set 做最新评论缓存
- 《DeepJIT: An End-To-End Deep Learning Framework for Just-In-Time Defect Prediction》论文笔记
- type_traits metaprogramming library learning
- [CV project debugging] CUDNN_CONVOLUTION_FWD_SPECIFY_WORKSPACE_LIMIT problem
- LeetCode每日一练 —— OR36 链表的回文结构
- [shell basics] determine whether the directory is empty
猜你喜欢

组件传值 provide/inject

Port inspection steps - 7680 port analysis - Dosvc service

Why don't you programmers make a living off your own projects?And have to work for someone else?
![[Swift] Customize the shortcut that pops up by clicking the APP icon](/img/d4/84b237995fc3d3700916eb57f6670d.png)
[Swift] Customize the shortcut that pops up by clicking the APP icon

Mysql 45 study notes (twenty-five) MYSQL guarantees high availability
![[C language] Three-pointed chess (classic solution + list diagram)](/img/64/18ed08b64f9618bbd7f24ee16e6a6f.jpg)
[C language] Three-pointed chess (classic solution + list diagram)

安全20220712

Use of QML

Recursive query single table - single table tree structure - (self-use)

C语言从入门到如土——数据的存储
随机推荐
Redis 使用 sorted set 做最新评论缓存
慧通编程第4关 - 魔法学院第6课
LeetCode每日一练 —— OR36 链表的回文结构
els 方块向右移动边界判断、向下加速
Select the smoke test case, and make the first pass for the product package entering QA
日志级别 和 打印log注意
[C language] General method for finding the sum of the greatest common factor and the least common multiple of two integers m and n, the classical solution
Bubble sort, selection sort, insertion sort, binary search directly
Why SocialFi achievement Web3 decentralized social in the future
Golang中的addressable
(线段树) 基础线段树常见问题总结
(tree) Last Common Ancestor (LCA)
type_traits metaprogramming library learning
Know the showTimePicker method of the basic components of Flutter
Observer pattern
Atomic operation CAS
[C language] General method of base conversion
volatile内存语义以及实现 -volatile写和读对普通变量的影响
Zotero如何删除自动生成的标签
A brief introduction to the CheckboxListTile component of the basic components of Flutter