2017-04-01 71 views
0

TestCase類的JavaScript是我initailize司機和調用URL「的說法是沒有定義」錯誤(URL「http://www.amazon.in/」)入門同時運行硒

public class TestCase { 
    InitializeDriver id = new InitializeDriver(); 
    WebDriver driver = null; 

    @BeforeTest 
    public void setup() 
    { 
     id.invokeApplicationUrl(); 
     driver = id.getDriver(); 

    } 

} 

TC1是我的測試去亞馬遜在頁籤

public class TC1 extends TestCase { 
    @Test 
    public void runTC1() 
    { 
     GoToSignInPage gts = new GoToSignInPage(driver); 
     gts.clickElement(); 
    } 
} 

邏輯去登錄頁寫在GoToSignPage寫入

public class GoToSignInPage { 

    WebDriver driver; 

    public GoToSignInPage(WebDriver driver) 
    { 
     this.driver=driver; 
    } 

    InitialPage ip = new InitialPage(driver); 
    InitializeDriver id = new InitializeDriver(); 

    public void clickElement() 
    { 
     Actions action = new Actions(driver); 
     //driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS); 
     JavascriptExecutor jse = (JavascriptExecutor)driver; 
     //ip.yourOrders(driver).click(); 
     jse.executeScript("argument[0].style.border='3px dotted blue'", ip.yourOrders(driver)); 
action.moveToElement(ip.yourOrders(driver)).moveToElement(ip.signInBt(driver)).click().build().perform(); 
} 

InitialPage類有所需的所有頁面對象

public class InitialPage { 

    WebDriver driver; 

    public InitialPage(WebDriver driver) 
    { 
     this.driver = driver; 
    } 

    WebElement element ; 

    public WebElement yourOrders(WebDriver driver) 
    { 
     element = driver.findElement(By.id("nav-link-yourAccount")); 
     return(element); 

    } 
    public WebElement signInBt(WebDriver driver) 
    { 
     element = driver.findElement(By.xpath(".//*[@id='nav-flyout-ya-signin']/a/span")); 
     return(element); 

    } 

} 

錯誤是如下

org.openqa.selenium.WebDriverException: unknown error: argument is not defined (Session info: chrome=56.0.2924.87) (Driver info: chromedriver=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf),platform=Windows NT 6.3.9600 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 22 milliseconds Build info: version: '3.0.0-beta1', revision: '8e4315c', time: '2016-07-28 18:04:05 -0700' System info: host: 'VAIO', ip: '192.168.0.6', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_45' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf), userDataDir=C:\Users\Akash\AppData\Local\Temp\scoped_dir6352_11834}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=56.0.2924.87, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: f74e69d9f66bab833287a8fd6f9d3021 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

回答

1

你的錯誤來自執行這段JavaScript代碼jse.executeScript("argument[0].style.border='3px dotted blue'",嘗試加載該網站在瀏覽器中(即鍍鉻),開放式開發工具(F12),導航到控制檯,輸入相同的命令,你會得到同樣的錯誤:

enter image description here

Selenium documentation

The arguments will be made available to the JavaScript via the "arguments" variable.

在您的代碼,您使用argument[0]而不是arguments[0]

+0

但我傳遞的參數,根據您的評論完整的命令如下 –

+0

,它看起來像要執行以下JavaScr ipt,'document.getElementById('nav-link-yourAccount')。style.border ='3px dotted blue''。順便說一句,這將導致另一個異常,如果沒有給定ID的元素,那麼,我會爲該 – oldbam

+1

添加另一個選項的檢查條件來嘗試,是改變爲'arguments [0]'注意:_s_在結尾這個變量,在你的代碼中缺少 – oldbam