51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 1664|回复: 6
打印 上一主题 下一主题

定位不到元素,哪位大神帮帮忙

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2016-10-21 11:44:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
假如操作过程如下,先登录,登录之后点击用户管理模块,然后点击新建,新建时会弹出窗口,就是在点击新建时报错
Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.xpath: //i[@class='icons-add-plus btn'] (tried for 60 second(s) with 500 MILLISECONDS interval)
Build info: version: '3.0.0', revision: '350cf60', time: '2016-10-13 10:48:57 -0700'
System info: host: 'K6PRCS9GK8OI27B', ip: '10.13.17.35', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_91'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, marionette=true, firefoxOptions={args=[], profile=UEsDBBQACAgIAB1bVUkAAAAAAAAAAAAAAAAHAAAAdXNlci5qc51WTW/bMAy971cMOW3AKqTretlOXdcBA4Z1aFDsKMgSbauRJU0fcfPvR/mjSRNHbndKbJMS+fj4yOjBUeugfLconGnxiXhWQvdf6oo0TLXMAQHNCgVi8eFtyZSH91/exJ2nYAFtrHEhudTAVKj7Z4JGG8ln/DWE1rg1qUOwxNbS19uz9Nky788U6CrU6Pjx8vK52xiwAybwR0AAHkB8l86HK4yFK0C34OJhuKbBvB4pr51pgHrupA3URU2DbJLLxXL6osAKTxAOfauvlfEwnc1oLUyrlWEC79KsSsDWpv1Tg14hWgmpaXeLQdng02W0MYKpGexhE4xRnoBzxnGjvVH7cB+n72WljUbUGmgKcKvu0edz8eC9RKtgkAsOfETcSgyUcsd8nfdVUq+JsaApPAZwmqlUzFczqExlvYt6+rIWCuHkBp8Z54DljBoz90gHysEFP4nEU6Wkt4ptQdycL1e/DDInlfbTtDG+Erf6j9RYX3++JBIvMvd3P9FjwQoTw+dCMb1eHHOuT4gypeiDRzBSnLKH/ji2RysRbrQlbS0DKOkDHvA3SneKCYkGaxnI0E0j6zC5xIUsAIphYbAB8lTzibfRkhq7xuLZtAXFUwdFl0q6OEg5VVt3rCHRYoGBaIS23N6jyat1JNrUSjfZ8IBHJ8MWmaIA/xEfnOSBGicrqak1SvJtnqoaWmw7MuSTqeazQPuTSXq5ikUju1b53b286sj4Mt2cPCab8VN3DoVJRUHLE+q160NMs+34e9yIpizRDs6YtZ4g+0xLiy0VULKowrScjLBzbwf+TEd7zIcs20Y6I/dRqYLbkl4ZO/uPc7bZo0dEbu5/XpELwnZFOk7vgW1YPyGyonpYirFH8jw6jtvBQzfEspf0NE3H5/PcQ5zFYL71SrDiSIIkOufLUxran0o1C/hIYQN6RkH3JuMtMmw2nEIZvu407UWF8sAcrwfazE3dhvTkJiI2Nls0JPmLqPiMLwYBclJMC+qRBh2Kz8X05tOL9dnYfciiEGdG8mB7QlmGFWd+t9kbnL4b67vBiQoUO6nOIpeYNR3EXuuYftJ1K9APfd1vKSeXs2Fk0U6sBMKoK5rkf4YkNeC05DXw9bder772X14/zQgTQqaI2cwgmNyZ/3dXVqaq0sthictK/14vdRlfozRitxZSJfZpWdVBnRh2e67jjf+jbHRsBNLgWtgRcZFWSQcHGO02mbR5IrFxf5xZZXZ9r0ofbb8B7JaMf1BLBwh1hce1pQMAALUMAABQSwECFAAUAAgICAAdW1VJdYXHtaUDAAC1DAAABwAAAAAAAAAAAAAAAAAAAAAAdXNlci5qc1BLBQYAAAAAAQABADUAAADaAwAAAAA=}, appBuildId=20160905130425, version=, platform=XP, proxy={}, specificationLevel=1, acceptSslCerts=false, browserVersion=45.4.0, platformVersion=6.1, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=Firefox, takesScreenshot=true, takesElementScreenshot=true, platformName=Windows_NT, device=desktop}]
Session ID: 0839da1a-5e6b-48e5-a6cc-c6898229c081
        at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:80)
        at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:265)
        at c3.web.selenium.webdriver.WebDriverTestCase.waitForElementByXpath(WebDriverTestCase.java:154)
        at c3.web.selenium.webdriver.WebDriverTestCase.findElementByXpath(WebDriverTestCase.java:278)
        at c3.web.pageObject.atomicEvent.createAtomicEvent.createEssential(createAtomicEvent.java:33)
        at c3.web.test.TestDemo.main(TestDemo.java:31)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: //i[@class='icons-add-plus btn']
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.0.0', revision: '350cf60', time: '2016-10-13 10:48:57 -0700'
System info: host: 'K6PRCS9GK8OI27B', ip: '10.13.17.35', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_91'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, marionette=true, firefoxOptions={args=[], profile=UEsDBBQACAgIAB1bVUkAAAAAAAAAAAAAAAAHAAAAdXNlci5qc51WTW/bMAy971cMOW3AKqTretlOXdcBA4Z1aFDsKMgSbauRJU0fcfPvR/mjSRNHbndKbJMS+fj4yOjBUeugfLconGnxiXhWQvdf6oo0TLXMAQHNCgVi8eFtyZSH91/exJ2nYAFtrHEhudTAVKj7Z4JGG8ln/DWE1rg1qUOwxNbS19uz9Nky788U6CrU6Pjx8vK52xiwAybwR0AAHkB8l86HK4yFK0C34OJhuKbBvB4pr51pgHrupA3URU2DbJLLxXL6osAKTxAOfauvlfEwnc1oLUyrlWEC79KsSsDWpv1Tg14hWgmpaXeLQdng02W0MYKpGexhE4xRnoBzxnGjvVH7cB+n72WljUbUGmgKcKvu0edz8eC9RKtgkAsOfETcSgyUcsd8nfdVUq+JsaApPAZwmqlUzFczqExlvYt6+rIWCuHkBp8Z54DljBoz90gHysEFP4nEU6Wkt4ptQdycL1e/DDInlfbTtDG+Erf6j9RYX3++JBIvMvd3P9FjwQoTw+dCMb1eHHOuT4gypeiDRzBSnLKH/ji2RysRbrQlbS0DKOkDHvA3SneKCYkGaxnI0E0j6zC5xIUsAIphYbAB8lTzibfRkhq7xuLZtAXFUwdFl0q6OEg5VVt3rCHRYoGBaIS23N6jyat1JNrUSjfZ8IBHJ8MWmaIA/xEfnOSBGicrqak1SvJtnqoaWmw7MuSTqeazQPuTSXq5ikUju1b53b286sj4Mt2cPCab8VN3DoVJRUHLE+q160NMs+34e9yIpizRDs6YtZ4g+0xLiy0VULKowrScjLBzbwf+TEd7zIcs20Y6I/dRqYLbkl4ZO/uPc7bZo0dEbu5/XpELwnZFOk7vgW1YPyGyonpYirFH8jw6jtvBQzfEspf0NE3H5/PcQ5zFYL71SrDiSIIkOufLUxran0o1C/hIYQN6RkH3JuMtMmw2nEIZvu407UWF8sAcrwfazE3dhvTkJiI2Nls0JPmLqPiMLwYBclJMC+qRBh2Kz8X05tOL9dnYfciiEGdG8mB7QlmGFWd+t9kbnL4b67vBiQoUO6nOIpeYNR3EXuuYftJ1K9APfd1vKSeXs2Fk0U6sBMKoK5rkf4YkNeC05DXw9bder772X14/zQgTQqaI2cwgmNyZ/3dXVqaq0sthictK/14vdRlfozRitxZSJfZpWdVBnRh2e67jjf+jbHRsBNLgWtgRcZFWSQcHGO02mbR5IrFxf5xZZXZ9r0ofbb8B7JaMf1BLBwh1hce1pQMAALUMAABQSwECFAAUAAgICAAdW1VJdYXHtaUDAAC1DAAABwAAAAAAAAAAAAAAAAAAAAAAdXNlci5qc1BLBQYAAAAAAQABADUAAADaAwAAAAA=}, appBuildId=20160905130425, version=, platform=XP, proxy={}, specificationLevel=1, acceptSslCerts=false, browserVersion=45.4.0, platformVersion=6.1, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=Firefox, takesScreenshot=true, takesElementScreenshot=true, platformName=Windows_NT, device=desktop}]
Session ID: 0839da1a-5e6b-48e5-a6cc-c6898229c081
*** Element info: {Using=xpath, value=//i[@class='icons-add-plus btn']}
        at sun.reflect.GeneratedConstructorAccessor8.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:127)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:93)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:42)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163)
        at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
        at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:368)
        at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:473)
        at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
        at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:360)
        at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:895)
        at org.openqa.selenium.support.ui.ExpectedConditions.access$000(ExpectedConditions.java:41)
        at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:205)
        at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:201)
        at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:238)
        ... 4 more
登录时的代码:
public static void login(String username,String password){
                getUserName().sendKeys(username);
                logger.info("password="+password);
                getPassword().clear();
                getPassword().sendKeys(password);
                getLoginObject().click();
                logger.info("login successful");
                logger.info("Title()="+webTest.getTitle());
//                closeParentWindow();
        }
新建时的代码:
public static void createEssential(String name,String event_code){
               
                webTest.findElementByXpath("//i[@class='icons-add-plus btn']").click();
                webTest.waitTime();
                webTest.findElementById("atomicevent_name").clear();
                webTest.findElementById("atomicevent_name").sendKeys(name);
                webTest.findElementById("atomicevent_event_code").clear();
                webTest.findElementById("atomicevent_event_code").sendKeys(event_code);
               
        }
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

  • TA的每日心情
    慵懒
    2021-12-24 13:41
  • 签到天数: 314 天

    连续签到: 1 天

    [LV.8]测试军长

    2#
    发表于 2016-10-21 13:46:16 | 只看该作者
    你可以在这行代码前面加个等待时间试试
    webTest.findElementByXpath("//i[@class='icons-add-plus btn']").click();

    评分

    参与人数 1测试积点 +10 收起 理由
    lsekfe + 10 积极回复获得测试积点10

    查看全部评分

    回复 支持 反对

    使用道具 举报

    该用户从未签到

    3#
     楼主| 发表于 2016-10-21 14:11:02 | 只看该作者
    加了等待时间,但还是不行,还发现有一个错
    Marionette: Element does not support any accessible actions -> id: , tagName: I, className: atomic-events-management-ico
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    4#
     楼主| 发表于 2016-10-21 14:19:48 | 只看该作者
    重定位句柄,但是还是不对
    public static  void closeParentWindow(){
                    logger.info("WindowHandle(1)="+webTest.getWindowHandle());
                    webTest.getDriver().manage().window().maximize();
                   
                    String currentWindow = webTest.getWindowHandle();
                    //得到所有窗口的句柄
                    Set<String> handles = webTest.getWindowHandles();
                    handles.remove(currentWindow);
                     String child_handle = (String)handles.iterator().next();
                     webTest.switchToWindow(currentWindow);
                     webTest.close();
                     webTest.setDriver(webTest.switchToWindow(child_handle));
                     
                    logger.info(webTest.getTitle()+","+webTest.getCurrentUrl());
            }
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    5#
     楼主| 发表于 2016-10-21 14:20:53 | 只看该作者
    加了等待时间也不对
    Marionette: Element does not support any accessible actions -> id: , tagName: I, className: atomic-events-management-icon
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    6#
    发表于 2016-10-25 09:55:07 | 只看该作者
    如果打开新的页面是新的frame,首先要跳到新的frame,否则一直在老的页面会一直找不到元素。 switch_to_frame("frame")
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    7#
     楼主| 发表于 2016-10-31 11:53:19 | 只看该作者
    是的,原来是嵌套在iframe标签中了
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-11-23 13:01 , Processed in 0.069062 second(s), 23 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

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