在Salesforce中无法通过Selenium定位nCino元素

时间:2019-02-13 04:30:03

标签: angularjs selenium-webdriver automation salesforce

我正在为我的项目使用nCino应用程序(在Salesforce上构建)。 nCino是一个基于Salesforce应用程序构建的框架,并在.c中调用。

我正在尝试通过Chrome浏览器中的Selenium Java(也在Firefox中尝试过)在nCino UI中自动执行功能流

问题1:切换到iframe并单击元素 请参阅下面的iframe代码

iframe Source code

控制台错误:

CORS policy error in console

Selenium代码段可切换到iframe,然后单击元素内部的元素:

package nCInoAutomation;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.apache.http.Header;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.html5.ApplicationCache;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Main {

	public static void main(String args[]) throws InterruptedException {
		  //System.setProperty("webdriver.gecko.driver", Parameters.FIREDRIVER);
		  System.setProperty("webdriver.chrome.driver", Parameters.CHROMEDRIVER);
		  ChromeOptions chromeOptions = new ChromeOptions();
		  chromeOptions.addArguments("--start-maximized"); 
		//  chromeOptions.addArguments("--disable-web-security"); 
		  WebDriver driver = new  ChromeDriver(chromeOptions);
		 driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
		//WebDriver driver = new FirefoxDriver();
		  
		  driver.get(Parameters.APPURL);
		  Thread.sleep(2000);
		  WebElement formElement = driver.findElement(By.id("login_form"));
		  formElement.findElement(By.id(Parameters.UNAME_XPATH)).sendKeys(Parameters.UNAME);
		  formElement.findElement(By.id(Parameters.PWD_XPATH)).sendKeys(Parameters.PWD);
		  formElement.findElement(By.id(Parameters.ENTER_XPATH)).sendKeys(Keys.ENTER);
		  Thread.sleep(20000);
		  System.out.println("Wait Over");
		  WebDriverWait wait=new WebDriverWait(driver, 20); 
		  
		  wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(2));
		  
		  List<WebElement> list = driver.findElements(By.tagName("iframe"));
		  System.out.println(list.size());
		  JavascriptExecutor js = (JavascriptExecutor) driver;
		  WebElement ele = list.get(2);
		  
		  js.executeScript("arguments[0].setAttribute('style', 'background: yellow; border: 2px solid red;');", ele);  
		  JavascriptExecutor jse = (JavascriptExecutor)driver;
		  jse.executeScript("window.scrollBy(0,500)", "");

		  System.out.println("********Switched to the iframe*******");
		 
		  wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='ncSecondaryNavigation']//span[text()='Loan'])[2]")));
		  System.out.println("Clicked");
	
		  
	}
}

It says that it has switched to iframe but doesnt look like so.

问题2:无法找到元素
另外,iframe包含大多数有角度的js元素,因此无法识别元素。参见下面的截图:

Source code of the page

应用程序如下所示:

Application Screenshot

您能帮我实现以下自动化吗? 1.登陆Salesforcw屏幕后,切换到iframe。 2.单击链接导航到“抵押”屏幕。

0 个答案:

没有答案