尝试识别 weblemnt 时出现超时异常 [英] Getting time out exception when trying to identify the webelemnt

查看:38
本文介绍了尝试识别 weblemnt 时出现超时异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码如下:

WebElement Username=d1.findElement(By.xpath("//*[@id='username']"));
Username.sendKeys("aadmin");

WebElement Password=d1.findElement(By.xpath("//*[@id='login_form']/tbody/tr/td/table/tbody/tr[12]/td[2]/input"));
Password.sendKeys("admin");

WebElement signin=d1.findElement(By.xpath("//*[@id='submit_']"));
signin.click();

System.out.println("User admin has logged in  "+ d1.getTitle());
w1.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='spaces-menu']/ul/li[1]"))).click();

System.out.println("User Admin clicks on Record button");

//Thread.sleep(5000);
d1.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

//Switching the control
int size2=d1.findElements(By.tagName("iframe")).size();
System.out.println("iframe size is---" + size2);

WebDriverWait w2= new WebDriverWait (d1, 15);       
//w2.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(0));
w2.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.tagName("iframe")));

System.out.println("Page title is     "+d1.getTitle());

//d1.switchTo().frame("iframe-page-container");

//d1.switchTo().frame(d1.findElement(By.tagName("iframe")));

WebDriverWait w3= new WebDriverWait (d1,30);

WebElement New=w3.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='capTypePopup']")));
    //WebElement New=w3.until(ExpectedConditions.visibilityOfElementLocated(By.className("menu-middle-normal-button")));
    //WebElement New=w3.until(ExpectedConditions.visibilityOfElementLocated(By.id("menuButtonContain-6")));
    //New.click();

    //d1.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    //JavascriptExecutor js = (JavascriptExecutor) d1;
    //WebElement element = d1.findElement(By.id("menuButtonContain-6"));

    //js.executeScript("arguments[0].setAttribute('type', '')",element);

    //System.out.println(d1.findElement(By.id("menuButtonContain-6")).getAttribute("value"));


    //Actions a1= new Actions(d1);
    //a1.moveToElement(New).click(New).build().perform();

    //d1.findElement(By.xpath("//*[@id='tr_menubar']/td"));
    //d1.findElement(By.xpath("//*[@id='capTypePopup']")).click();
    //w1.until(ExpectedConditions.elementToBeClickable(By.className("portlet-menu-item"))).click();
    //w2.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='capTypePopup']/font"))).click();
    System.out.println("Click on the new button");

下面是页面的 DOM,我试图点击 iframe 内的新建按钮.

Below is the DOM of the page, i am trying to click on New button which inside the iframe.

在此处输入图片说明

推荐答案

xpath:

//div[@id='capTypePopup']

你使用的会找到多个元素,selenium 会使用第一个 find 元素,这可能不是你所期望的.

you used will find more than one elements,selenium will use the first find element, which may be not the one your expected.

从您的屏幕截图中,我注意到已经有两个,我想在您想要的 div 之前应该还有另一个,并且它不可见.

From your screenshot, i noticed there are already two, I guess there should be another one ahead of the div your desired and it's not visible.

使用Dev工具测试//div[@id='capTypePopup'],确认第一个找到的div是否可见.

Use Dev tool to test the //div[@id='capTypePopup'], and confirm the first found div is visible or not.

如果不可见,请使用更严格的 xpath,它可以找到您想要的 div.在那之后,您的问题应该消失了.

If not visible, use more strict xpath which can find the div you desired. After that your problem should gone.

这篇关于尝试识别 weblemnt 时出现超时异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆