当前位置:网站首页>For the first time, I suspect that there is a bug in selenium4 because the iframe element is not found?
For the first time, I suspect that there is a bug in selenium4 because the iframe element is not found?
2022-08-11 08:12:00 【I tested first】
前因
Since the beginning of selling skills in Xianyu,More than a dozen or 20 visitors have come to pay for answers,I am not very honored either、受宠若惊,
But one thing is not so beautiful,Great value for money for those looking for answers,But it is a loss for the subject,甚至是亏本;
不论如何,All in all, it's kind of worth it,can be found by those in need,To prove that their skills are valuable and needed,很不错.
后果
What I am best at ispython/java自动化测试领域,Naturally, it is in the line of automation,But it has also received a lot of demand from other fields;
譬如:matplotlib、flask、django、numpy、nltk等等方面,Of course, some learning costs are low,Can be dealt with in an emergency;
Sometimes aboutwebDevelopment is a bit stretched,every time you assess your needs,must build the environment,And this cost is not billed.
正题
It's hard to come up with a list of solutions to automated testing problems,不管是接口还是UI自动化,I don't have the above troubles;Because the development environment is ready-made,But the tested environment is varied.
- 需求
UI自动化:模拟登录163邮箱,Why does the browser open every time,But can't enteraccount/passwd?
- 分析1
Now that it has come to the point of opening the browser,Then you cannot enter the account operation?It is nothing more than that the element cannot be found,When I saw her code,我整个人都不淡定了.
- 代码1:测试用例类
import unittest
from login import PageLogin
class TestLogin(PageLogin):
def testcaselogin(self):
username = "XXXXX"
PWD = "XXXXXX"
def page_login(self,username,password):
username = "XXXXXX"
PWD = "xxxxxXX"
self.page_input_username(username)
self.page_input_password(PWD)
self.page_click_login_btn()
- 代码2:The encapsulated page operation class
from base.basepage import Base
class PageLogin(Base):
#登录
def page_click_login_link(self):
self.base_click(page.login_link)
#输入用户名
def page_input_username(self,email):
self.base_input(page.login_username,email)
login_username = By.name,"email"
#输入密码
def page_input_password(self,password):
self.base_input(page.login_password,password)
login_pwd = By.name,"password"
#点击登录
def page_click_login_btn(self):
self.base_click(page.login_btn)
login_btn = By.id,"dologin"
- 分析2
From the above code level,A test case is executed(I saw it remotely to find out what she was usingvc编辑器),Of course you can only open the browser,
因为它是继承了PageLogin类,There is an open address operation,In the current test class, the open operation is not performed,But it didn't perform the account operation for the second reason;
原因就是:page.login_password,This element is also annotated,The entire test case simply cannot find the element to operate on;
- PO设计模式实现的UI自动化测试框架,It feels like her code is cobbled together,And still don't fully understand this design pattern.
解决
In line with the mission of collecting people's money and people's disaster relief,解决这类问题,Ask yourself or you can do it!
- Facts have proven themselves wrong,Though the idea is fine,But the direction may be deviated.
pageI filled her with the elements,Fortunately, these page elements are simple,都是有id或者name的.
Just because she used itselenium4的版本,This made me suspect at one point that it was a problem,The subject has also been unable to locate the element?
- 思考:都是id或者nameThere is no reason why the element cannot be located,There must have been an oversight.
I also thought about itframe或iframe标签,But for the first timeF12's source code search yielded no results?
- Makes me suspiciousselenium4,Use it immediately when you get homeselenium3版本试了一下,大失所望!Finally confirmed itiframe的问题,Open a browser and enter the destination address,It is not specifiediframeManipulate elements on this tag,Direct manipulation is invalid,As a result, the code keeps reporting an error that the page element cannot be found and times out.
代码
From asking a question to confirming it、找到问题、解决问题,The time cost is quite high,Because only received9.9元.
- The modified test class
import unittest
from page.login import PageLogin
class TestLogin(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.PL = PageLogin()
def test_page_login(self):
username = "XXXXXX"
PWD = "XXXXXXXX"
self.PL.switch_iframe()
self.PL.page_input_username(username)
self.PL.page_input_password(PWD )
self.PL.page_click_login_btn()
if __name__ == '__main__':
unittest.main()
- Add methods to the base class
def switch_iframe(self):
self.driver.switch_to.frame(self.driver.find_elements(By.TAG_NAME, "iframe")[0])
# self.driver.switch_to.frame(self.base_find_element((By.XPATH,"//iframe[starts-with(@id,'x-URS-iframe')]")))
# self.driver.switch_to.frame(0)
# self.driver.switch_to.frame("id or name")
总结
So don't be arrogant,戒骄戒躁,不要粗心,It was really a problem that could be solved in a few minutes,to waste1整天.
对于UIThe problem with automation is nothing more than solving the problem of positioning page elements,As for what to think:How to find this element,How to write the best lookingxpath表达式等等,This requires practice.
边栏推荐
猜你喜欢

leetcode:69. x 的平方根

机器学习(二)线性回归

囍楽cloud task source code

Hibernate 的 Session 缓存相关操作

如何通过 IDEA 数据库管理工具连接 TDengine?

C Primer Plus(6) 中文版 第1章 初识C语言 1.7 使用C语言的7个步骤
1.1-回归

查询跟踪快递单号物流,智能分析物流中转有延误的单号

IQUNIX A80 exploring TTC金粉 初体验

TF generates (feature, label) set through feature and label, tf.data.Dataset.from_tensor_slices
随机推荐
【LeetCode】链表题解汇总
C Primer Plus(6) 中文版 第1章 初识C语言 1.1 C语言的起源 1.2 选择C语言的理由 1.3 C语言的应用范围
欧拉函数(用欧拉筛法求欧拉函数)
【LeetCode】Summary of linked list problems
2022-08-10 mysql/stonedb-慢SQL-Q16-耗时追踪
opengauss创建用户权限问题
对比学习系列(三)-----SimCLR
选择收银系统主要看哪些方面?
剑指offer专项突击版第26天
nodejs微服务中跨域,请求,接口,参数拦截等功能
Decrement operation in tf; tf.assign_sub()
2022-08-10:为了给刷题的同学一些奖励,力扣团队引入了一个弹簧游戏机, 游戏机由 N 个特殊弹簧排成一排,编号为 0 到 N-1, 初始有一个小球在编号 0 的弹簧处。若小球在编号为 i 的弹
The softmax function is used in TF;
查找最新人员工资和上上次人员工资的变动情况
【Day_13 0509】▲跳石板
jenkins简单使用
2021-08-11 For loop combined with multi-threaded asynchronous query and collect results
支持各种文件快速重命名最简单的小技巧
Kotlin算法入门计算素数以及优化
Kotlin算法入门求回文数数算法优化二数字生成规则