120秒后超时,等待By.id定位的元素的可见性 - 硒中的错误

时间:2015-12-11 22:17:40

标签: selenium-webdriver

我在120秒后等待通过By.id找到元素的可见性时出现超时:可拖动的错误消息。我想拖拉。 该页面的链接是 - http://way2automation.com/way2auto_jquery/droppable.php 请帮忙。

网页是:

    <style id="firepath-matching-node-style" type="text/css">.firepath-    matching-node { outline: 2px dashed #00F;}</style>
</head>
<body style="cursor: auto;">
<div id="draggable" class="ui-widget-content ui-draggable ui-draggable-    handle" style="position: relative; width: 100px; right: auto; height: 100px; bottom: auto; left: 9px; top: -3px;">
<p>Drag me to my target</p>
</div>
<div id="droppable" class="ui-widget-header ui-droppable">
</body>
Code :

    WebDriverWait wait = new WebDriverWait(driver, 60);// 1 minute 
 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//[@id='wrapper']/div[2]/div[2]/div[1]/ul/li[2]/a/figure")));
    WebElement droppable = driver.findElement(By.xpath(".//*[@id='wrapper'/div[2]/div[2]/div[1]/ul/li[2]/a/figure"));
    droppable.click();
    WebDriverWait wait1 = new WebDriverWait(driver, 120);// 1 minute 
    wait1.until(ExpectedConditions.visibilityOfElementLocated(By.id("draggable")));
    WebElement drag = driver.findElement(By.id("draggable"));
    WebElement drop = driver.findElement(By.xpath(".//*[@id='droppable']"));
    (new Actions(driver)).dragAndDrop(drag,drop).perform();

1 个答案:

答案 0 :(得分:1)

根据该网站,拖放元素位于iframe内。您需要将webdriver切换到iframe,然后才能进行拖放操作。

在处理拖放之前尝试这样做:

driver.switchTo().frame(0);