2016-12-06 48 views
0

幫助我在使用javascript時點擊「arguments [index] .click()」的索引來點擊Selenium WebDriver中的隱藏按鈕日食)如何在Selenium WebDriver(Eclipse)中更改「arguments [index] .click()」的索引

這是我的代碼:

public page_ProductInfo Buy(int i) { 
 
\t \t JavascriptExecutor js = (JavascriptExecutor) driver; \t \t 
 
\t \t WebElement ButtonBought = driver.findElement(By.xpath(
 
\t \t \t \t "//button[@class='c-quick-buy__button c-button c-button_size_big c-button_color_old-orange c-button_js_inited']")); 
 
\t \t String index=Integer.toString(i); 
 
\t \t 
 
\t \t String script = "arguments["+index+"].click();"; 
 
\t \t 
 
\t \t js.executeScript(script, ButtonBought); 
 
\t \t 
 
\t \t return new page_ProductInfo(driver); 
 

 
\t }

和錯誤消息:

FAILED: f 
 
org.openqa.selenium.WebDriverException: unknown error: Cannot read property 'click' of undefined

回答

0

您使用WebElement ButtonBought = driver.findElement(By.xpath(,所以ButtonBought是一個單一的元素,我想js.executeScript作品與arguments[0]

請嘗試找到的元素列表,而不是:

List<WebElement> ButtonBought = driver.findElements(By.xpath(
相關問題