[英]Java error in Eclipse - soundresource cannot be resolved to a variable
[英]Error: Driver cannot be resolved to a variable- selenium java eclipse
我試圖習慣於使用Selenium進行自動化測試。 到目前為止,我已經成功完成了該測試用例的所有方面,除了最后一步是檢查警報是否存在(已收到事務確認)
我試圖使用布爾值來執行此功能,但我一直收到相同的錯誤:無法將驅動程序解析為變量。
有什么建議么?
package com.scotia.test;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
public class ScotiaTest1 {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","/Users/theone/Downloads/chromedriver-new");
// Create a new instance of the Chrome driver
WebDriver driver = new ChromeDriver();
//Login using Username and Password
driver.get("https://LEAP:Password10@apps.scotiabank.com/LEAP_Prototype/desktop/html/Chile_index.html#");
//Wait for 5 Sec
Thread.sleep(2000);
//Find Proximity Serie A link and click on it
driver.findElement(By.cssSelector("#investing_tab tr:nth-child(7) a.acct-name")).click();
//Wait for 5 Sec
Thread.sleep(2000);
//Find New Funds Button and click on it
driver.findElement(By.cssSelector(".pad-top-10.txt-right .btn.action-btn")).click();
//Wait for 5 Sec
Thread.sleep(2000);
//Select Field Rescue investment and choose Rescue
Select dropdown = new Select(driver.findElement(By.id("mf_action")));
dropdown.selectByVisibleText("Inversión");
//Wait for 5 Sec
Thread.sleep(2000);
//Select Field Current account and choose current account
dropdown = new Select(driver.findElement(By.id("selaccount_drpdown")));
dropdown.selectByVisibleText("Cuenta Corriente *** 0002 USD 10.000,00");
//Wait for 5 Sec
Thread.sleep(2000);
//Select Field Fund Type and choose medium term
dropdown = new Select(driver.findElement(By.id("term")));
dropdown.selectByVisibleText("Mediano Plazo");
//Wait for 5 Sec
Thread.sleep(2000);
//Select Field Mutual Fund Name and choose Proximity Series A
dropdown = new Select(driver.findElement(By.id("typefund")));
dropdown.selectByVisibleText("Proximidad Serie A");
//Wait for 5 Sec
Thread.sleep(2000);
//Select Field Fund account Name and choose 001
dropdown = new Select(driver.findElement(By.id("sub_accnt")));
dropdown.selectByVisibleText("001");
//Wait for 5 Sec
Thread.sleep(2000);
//Select Field Rode and type 222
driver.findElement(By.id("amount_field")).sendKeys("222");
//Wait for 5 Sec
Thread.sleep(2000);
//Find to Accept Button and click on it
driver.findElement(By.id("next")).click();
//Wait for 5 Sec
Thread.sleep(2000);
//Find to Confirm Button and click on it
driver.findElement(By.id("next")).click();
//Wait for 5 Sec
Thread.sleep(2000);
// Print a Log In message to the screen
//Wait for 5 Sec
Thread.sleep(2000);
}
public boolean isAlertPresent(){
try{
Alert a = new WebDriverWait(driver, 10).until(ExpectedConditions.alertIsPresent());
if(a!=null){
System.out.println("Alert is present");
driver.switchTo().alert().accept();
return true;
}else{
throw new Throwable();
}
}
catch (Throwable e) {
System.err.println("Alert isn't present!!");
return false;
}
//Wait for 5 Sec
Thread.sleep(2000);
}
}
這是您正在使用的實際代碼嗎? 它有很多問題:不會調用isAlertPresent(),在那里使用驅動程序,但它不是類的字段,依此類推。(因此,出現“錯誤:無法將驅動程序解析為變量”)
我將其修改為可運行的(將isAlertPresent()
合並到main()
),最后得到了綠色的“警報”。 你是那個意思嗎 如果是,那么它不是警報,而是一個div,所以要代替這個:
Alert a = new WebDriverWait(driver, 10).until(ExpectedConditions.alertIsPresent());
寫這樣的東西:
WebElement div = new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.className("success-msg")));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.