Java自学者论坛

 找回密码
 立即注册

手机号码,快捷登录

恭喜Java自学者论坛(https://www.javazxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,会员资料板块,购买链接:点击进入购买VIP会员

JAVA高级面试进阶训练营视频教程

Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程Go语言视频零基础入门到精通Java架构师3期(课件+源码)
Java开发全终端实战租房项目视频教程SpringBoot2.X入门到高级使用教程大数据培训第六期全套视频教程深度学习(CNN RNN GAN)算法原理Java亿级流量电商系统视频教程
互联网架构师视频教程年薪50万Spark2.0从入门到精通年薪50万!人工智能学习路线教程年薪50万大数据入门到精通学习路线年薪50万机器学习入门到精通教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程MySQL入门到精通教程
查看: 448|回复: 0

【Selenium-WebDriver自学】出现的问题和解决方案(十七)

[复制链接]
  • TA的每日心情
    奋斗
    2024-11-24 15:47
  • 签到天数: 804 天

    [LV.10]以坛为家III

    2053

    主题

    2111

    帖子

    72万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    726782
    发表于 2021-5-10 16:22:57 | 显示全部楼层 |阅读模式

     

     

    ==========================================================================================================

     

        写在前面:

     

        从开始学习Selenium和Webdriver开始,就会遇到各种问题,遇到问题就解决问题,所以这一个阶段也是不断的完善过程中。

     

    ==========================================================================================================

     

     

    1. 报错:
    org.openqa.selenium.firefox.NotConnectedException

    原因:
    FireFox和Selenium的版本不匹配导致
    webdriver启动firefox时如果遇到以下错误,则说明selenium的版本和firefox不兼容了,需要升级selenium:
    Selenium ->FireFox
    2.25.0 -> 18
    2.30.0 ->19
    2.31.0 ->20
    升级selenium jar包
    正常启动firefox
    http://blog.csdn.net/sinat_29741049/article/details/57405191
    http://ftp.mozilla.org/pub/firefox/releases/

    证明:
    2.52.0->43.0Firefox
    可以正常启动

    2.alert处理
    http://www.cnblogs.com/qiaoyeye/p/5593428.html

    [org.openqa.selenium.UnhandledAlertException: unexpected alert open: {Alert text : 确认删除此客户吗?}
    (Session info: chrome=59.0.3071.104)
    (Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 6 milliseconds: null
    Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:03:33'
    System info: host: 'WIN-UBMLJ97RGF8', ip: '172.16.0.108', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'
    Driver info: org.openqa.selenium.chrome.ChromeDriver
    Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41), userDataDir=C:\Users\ADMINI~1\AppData\Local\Temp\scoped_dir16596_23783}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=59.0.3071.104, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
    Session ID: 5228d8eb9d66ab2a0d06aa25837dabb2]

    3.@test的执行顺序问题:
    http://blog.csdn.net/d6619309/article/details/52755578
    在xml里面使用<include>指定需要执行的方法和顺序
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
    <suite name="Preserve order test runs">
    <test name="Regression 1" preserve-order="true">
    <classes>
    <class name="com.pack.preserve.ClassOne">
    <methods>
    <include name="B" />
    <include name="A" />
    </methods>
    </class>
    </classes>
    </test>
    </suite>

    4.Eclipse出现乱码问题解决
    http://blog.csdn.net/tfy1332/article/details/22151491
    是因为编码格式的问题引起的,GBK修改为UTF8格式。

    5.Eclipse里,中文字体太小问题
    http://jingyan.baidu.com/article/72ee561aa6bc28e16038df6e.html

    6.上传图片的怎么写?
    http://www.cnblogs.com/joewu/p/3701121.html
    利用webdriver上传文件非常方便
     /*上传文件
      * element,上传按钮 例  ("//input[@type='file']")
      * filePath,文件路径,例 C:\\testContent.pdf
     */
     public void fileUpload(String element, String filePath){
      driver.findElement(By.xpath(element)).sendKeys(filePath);  
     }

    7.文件选择图片

    http://blog.csdn.net/xie_0723/article/details/50617100
    http://blog.csdn.net/lily_xl/article/details/51723407
    http://blog.csdn.net/huilan_same/article/details/52208363

    [2017-07-18 16:22:41:192] [videoyiTestCase.ProductManagerTest] [ERROR] [113] [org.openqa.selenium.ElementNotVisibleException: element not visible
    (Session info: chrome=59.0.3071.104)
    (Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 50 milliseconds
    Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:03:33'
    System info: host: 'WIN-UBMLJ97RGF8', ip: '172.16.0.108', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'
    Driver info: org.openqa.selenium.chrome.ChromeDriver
    Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41), userDataDir=C:\Users\ADMINI~1\AppData\Local\Temp\scoped_dir12900_16704}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=59.0.3071.104, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
    Session ID: 91aae86160d186c5daeec9631c25f830]

    http://www.cnblogs.com/qixue/p/3928775.html
    打开文件夹后,上传文件夹不能正常关闭。
    http://blog.sina.com.cn/s/blog_539a70d30101ajsg.html
    http://www.360doc.com/content/16/0627/09/31226932_571055470.shtml
    http://www.360doc.com/content/15/1014/15/20107535_505596449.shtml

    3:windows弹窗
    例如:

    思路: 

    解决的方法可以通过第三方的工具:autoit 来处理。具体方法请自行百度搜索autoit。
    http://www.cnblogs.com/fnng/p/4188162.html
    java http://www.cnblogs.com/testlc/p/6069460.html
    http://blog.csdn.net/lily_xl/article/details/51723407

    将上传的文件地址参数化:
    http://blog.csdn.net/huilan_same/article/details/52208363
    通过autoit的获取对象并编辑脚本:

    ControlFocus("文件上传", "", "Edit1")
    WinWait("[CLASS:#32770]", "", 10)
    ControlSetText("文件上传" ,"", "Edit1", $CmdLine[1])
    Sleep(2000)

     


    使用方法不正确导致的错误
    String strUploadExePath = "E:\\Yingpu\\000.SVNYP\\01.个人文件夹\\Renqiang\\04.AutoTest\\videoyiAutoTest\\lib\\uploadFile.exe";
    String strResourcePath = "E:\\Yingpu\\000.SVNYP\\01.个人文件夹\\Renqiang\\04.AutoTest\\videoyiAutoTest\\resource\\百科展示图片_580_660.png";
    Runtime.getRuntime().exec(strUploadExePath + " " + strResourcePath);

     

    8.获得当前java运行的工作路径
    方便拼接字符串等使用
    http://blog.csdn.net/xionglangs/article/details/51085307


    9.找不到元素时,报错
    is not clickable at point (209, 606). Other element would receive the click
    https://stackoverflow.com/questions/11908249/debugging-element-is-not-clickable-at-point-error


    10.Chrome已经跑通的Case,在FireFox上上传文件时,跑不通
    [org.openqa.selenium.NoSuchElementException: Element is not currently visible and so may not be interacted with

    https://stackoverflow.com/questions/20046783/org-openqa-selenium-nosuchelementexception-no-such-element


    11.关闭子窗口
    http://blog.csdn.net/gloria0610/article/details/54691685
    public static void closeSubWindow(WebDriver driver){
    // Get all window handles
    Set<String> handles = driver.getWindowHandles();
    // Save main Window
    String mainWindowhandle = driver.getWindowHandle();
    // sub window hanlde
    String detailWindowHandle = null;
    Iterator<String> iterator = handles.iterator();
    while(iterator.hasNext()){
    String key = iterator.next();
    if (mainWindowhandle.equals(key)){
    continue;
    }
    detailWindowHandle = key;
    }
    WebDriver detailWindow = driver.switchTo().window(detailWindowHandle);
    detailWindow.close();
    handles.remove(detailWindowHandle);
    driver = driver.switchTo().window(mainWindowhandle);
    }

    12.WebDriver获得元素的禁用状态

     以后遇到新的问题,还会记录。

     

    哎...今天够累的,签到来了1...
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|小黑屋|Java自学者论坛 ( 声明:本站文章及资料整理自互联网,用于Java自学者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

    GMT+8, 2024-12-23 03:36 , Processed in 0.056439 second(s), 27 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表