Robot Framework - Selenium Webdriver - Java:有人讓我知道爲什麼當調用全局變量到我的函數時,我得到陳舊的元素引用異常。機器人框架 - Selenium Webdriver - Java:調用全局變量時的陳舊元素引用異常
我已經創建了下面的java方法,並在Robot框架中調用了這個關鍵字。
public String CreateOpportunity()
{
String OpportunityName = "Optimum Wartung"+RandomNumber();
WaitAndClickElement("id",SalesforceOpportunityPageData.OpportunityTab);
ClickOnElement("cssSelector", SalesforceOpportunityPageData.NewButton);
SelectDropDownValues ("id",SalesforceOpportunityPageData.SiteCountryField,SalesforceOpportunityPageData.SiteCountryValue);
EnterValues("id",SalesforceOpportunityPageData.ProjectEndDateField,SalesforceOpportunityPageData.ProjectEndDateValue);
ClickOnElement("cssSelector",SalesforceOpportunityPageData.SaveButton);
return OpportunityName;
}
public void BeginAssess(String opportunityStr){
//opportunityString=CreateOpportunity(opportunityStr);
List<WebElement> opportunities = driver.findElements(By.xpath("//a[contains(@id,'offer-item')]"));
System.out.println("Entered into Begin Asses function "+ opportunityStr);
for(WebElement opportunite:opportunities)
{
WebElement textele = opportunite.findElement(By.cssSelector("div.offer-name.no-contracts"));
String textval = textele.getText();
System.out.println("TextValue is: " + textval);
if(textval.equalsIgnoreCase(opportunityStr))
{
WaitTillElementToBeClickable("cssSelector",CustomerPageData.OpportunityStatus);
opportunite.findElement(By.cssSelector("div.opportunity-status")).click();
System.out.println("Its clicked2");
}
}
}
public void WaitTillElementToBeClickable(String locatorType,String locatorVaue)
{
try{
WebDriverWait wait = new WebDriverWait(driver,200);
if(locatorType.equalsIgnoreCase("cssSelector"))
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(locatorVaue)));
else if(locatorType.equalsIgnoreCase("xpath"))
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(locatorVaue)));
else if(locatorType.equalsIgnoreCase("id"))
wait.until(ExpectedConditions.elementToBeClickable(By.id(locatorVaue)));
}
catch(Exception e){
System.out.println("Webdriver Locator Error"+e);
}
}
以下是RF代碼。我創建了一個變量$ {Oppo}並將其設置爲全局變量,如下所示。並將該變量傳遞給名爲「Begin Assess」的關鍵字。它執行代碼,但以陳舊的元素異常結束。我已經把等待條件,但它仍然有相同的情況。幫助我,我要去哪裏錯了。 注意:我沒有使用selenium2library。只使用硒webdriver。
*** Variable ***
${Oppo}
*** Test Cases ***
Create Opportunities in Salesforce Environment
Logon To Salesforce
${Oppo}= Create Opportunity
Set Global Variable ${Oppo}
Logon To KCC With Valid Credentials
Logon To KCC
Verify the Salesforce Data is synchronized with KCC tool
Update KCC Data
Complete The Assessment For An Opportunity
Search Customer Account Automation
Expand Customer Account
Begin Assess ${Oppo}
更正代碼:
public void BeginAssess(String opportunityStr){
//opportunityString=CreateOpportunity(opportunityStr);
List<WebElement> opportunities = driver.findElements(By.xpath("//a[contains(@id,'offer-item')]"));
System.out.println("Entered into Begin Asses function "+ opportunityStr);
for(WebElement opportunite:opportunities)
{
WebElement textele = opportunite.findElement(By.cssSelector("div.offer-name.no-contracts"));
String textval = textele.getText();
System.out.println("TextValue is: " + textval);
if(textval.equalsIgnoreCase(opportunityStr))
{
WaitTillElementToBeClickable("cssSelector",CustomerPageData.OpportunityStatus);
opportunite.findElement(By.cssSelector("div.opportunity-status")).click();
System.out.println("Its clicked");
break;
}
}
}
當使用Chrome,Firefox,IE等不同瀏覽器時,您是否得到相同的錯誤? – Helio
您可以在一個測試用例中設置變量,然後下面的測試用例將您記錄到某個東西中。你確定從你設置變量的地方沒有頁面刷新到你使用它的地方嗎? –
我想,在這種方法 - BeginAssess,點擊行動後打破循環。讓我知道它是否工作 – Karthikeya