2012-02-10 96 views
0

這是我的腳本。同時點擊一個使用其xpath的鏈接不工作&會拋出一個錯誤「找不到ERROR元素」,但在Selenium IDE中運行良好。錯誤:未找到元素在Selenium IDE中運行良好,但在Selenium RC中未運行。獲取錯誤

import com.thoughtworks.selenium.*; 
import org.junit.After; 
import org.junit.Before; 
import org.junit.Test; 
import java.util.regex.Pattern; 

public class testGoogle extends SeleneseTestCase { 
@Before 
public void setUp() throws Exception { 
    selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.google.co.in/"); 
    selenium.start(); 
    selenium.windowFocus(); 
    selenium.windowMaximize(); 
} 

@Test 
public void testUntitled() throws Exception { 
    selenium.open("http://www.google.co.in/"); 
    selenium.waitForPageToLoad("30000"); 
    assertEquals("Google", selenium.getTitle()); 
    selenium.click("name=q"); 
    selenium.type("name=q", "Software Testing"); 
    selenium.click("name=btnK"); 
    selenium.click("//html/body/div[4]/div/div/div[4]/div[3]/div[2]/div/div[2]/div/ol/li[2]/div/h3/a"); // ERROR: Element Not Found 

    selenium.waitForPageToLoad("30000"); 

} 

@After 
public void tearDown() throws Exception { 
    selenium.stop(); 
} 
} 

回答

0

您可以檢測鏈路爲selenium.click( 「鏈接= XYZ」),而不是XPath的

0

的腳本是絕對正確的。但問題是它運行速度非常快。當您啓動腳本時,所有元素都未完全加載。因此,添加

selenium.setSpeed(「1000」);

作爲函數的第一行testUntitled()。你的腳本運行良好。

乾杯, 阿米特釋迦

0

這樣

xpath=/html/body/div[4]/div/div/div[4]/div[3]/div[2]/div/div[2]/div/ol/li[2]/div/h3/a 

它會奏效這一問題早些時候所面臨的路徑之前,只需添加 「的XPath =」 ..

0

我也面臨這個問題 - Selenium RC中的「元素未找到」。

使用selenium.setSpeed("1000")工作。

相關問題