当前位置:网站首页>已解决(最新版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")
边栏推荐
- errno error code and meaning (Chinese)
- (Line segment tree) Summary of common problems of basic line segment tree
- The application and practice of mid-to-platform brand advertising platform
- 浅识Flutter 基本组件之showDatePicker方法
- VS QT - ui does not display newly added members (controls) || code is silent
- 进程间通信
- (4) Recursion, variable parameters, access modifiers, understanding main method, code block
- web容器及IIS --- 中间件渗透方法1
- Good place to download jar packages
- 分布式锁以及实现方式三种
猜你喜欢
SIP Protocol Standard and Implementation Mechanism
"DeepJIT: An End-To-End Deep Learning Framework for Just-In-Time Defect Prediction" paper notes
IDEA comment report red solution
浅识Flutter 基本组件之CheckboxListTile组件
What skills do I need to learn to move from manual testing to automated testing?
The application and practice of mid-to-platform brand advertising platform
(5) final, abstract class, interface, inner class
No qualifying bean of type question
《DeepJIT: An End-To-End Deep Learning Framework for Just-In-Time Defect Prediction》论文笔记
Know the showTimePicker method of the basic components of Flutter
随机推荐
SocialFi 何以成就 Web3 去中心化社交未来
(六)枚举、注解
C primer plus study notes - 8, structure
Postgresql 15 source code analysis (5) - pg_control
The use of beforeDestroy and destroyed
浅识Flutter 基本组件之CheckBox组件
Component pass value provide/inject
Summary of Huawei Distributed Storage FusionStorage Knowledge Points [Interview]
Automation strategies for legacy systems
postgresql 15源码浅析(5)—— pg_control
Zotero如何删除自动生成的标签
"DeepJIT: An End-To-End Deep Learning Framework for Just-In-Time Defect Prediction" paper notes
ClickHouse: Setting up remote connections
type_traits元编程库学习
web容器及IIS --- 中间件渗透方法1
els 方块向右移动边界判断、向下加速
Detailed explanation of TCP (1)
Observer pattern
C language from entry to such as soil, the data store
Why don't you programmers make a living off your own projects?And have to work for someone else?