当前位置:网站首页>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.
边栏推荐
猜你喜欢
1071 Small Gamble (15 points)
matrix multiplication in tf
查找最新人员工资和上上次人员工资的变动情况
go-grpc TSL authentication solution transport: authentication handshake failed: x509 certificate relies on ... ...
【云原生】云原生在网络安全领域的应用
零基础SQL教程: 基础查询 05
9、Neural Sparse Voxel Fields
Machine Learning Summary (2)
1036 Programming with Obama (15 points)
Redis 只会用缓存?20种妙用让同事直呼牛X(荣耀典藏版)
随机推荐
Filesystem Hierarchy Standard
如何通过 IDEA 数据库管理工具连接 TDengine?
JUC Concurrent Programming
一根网线两台电脑传输文件
1076 Wifi Password (15 points)
Use tf.argmax in Tensorflow to return the index of the maximum value of the tensor along the specified dimension
机器学习(一)数据的预处理
My creative anniversary丨Thank you for being with you for these 365 days, not forgetting the original intention, and each is wonderful
Four states of Activity
欧拉函数(用欧拉筛法求欧拉函数)
XXL-JOB 分布式任务调度中心搭建
企业服务器主机加固现状分析
1.2 - error sources
Write a resume like this, easy to get the interviewer
装饰器模式:Swift 实现
4.1 - Support Vector Machines
场地预订系统,帮助场馆提高坪效
1061 True or False (15 points)
支持各种文件快速重命名最简单的小技巧
2.1 - Gradient Descent