Here is a div with an AngularJS ng-click attribute that sets a variable when the div is clicked.
<div id="id"
ng-click="foo.bar = true;">
Set bar variable on foo object to true
</div>
Here is some Java code that uses Selenium to click on the div element.
By upload = By.id("id");
driver.findElement(uploadCensus).click();
When I run the Java code, the AngularJS hangs for eternity. I figure foo.bar is not set when the div is clicked so here is some code that sets the variable directly.
By upload = By.id("id");
((JavascriptExecutor) driver)
.executeScript("foo.bar = true;",
driver.findElement(upload));
Stacktrace
unknown error: foo is not defined (Session info: chrome=56.0.2924.87) (Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 51 milliseconds Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58' System info: host: 'WV-VC104-027', ip: '{ip}', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_151' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed), userDataDir=C:\Users{user}\AppData\Local\Temp\scoped_dir5600_4225}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=56.0.2924.87, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: a7734312eff62fe452a53895b221a58d
When I try to set foo.bar I cannot get a reference to the variable because it is not globally defined and is buried somewhere inside AngularJS source code. I have tried to unminify the index and look for the variable but I cannot seem to find it. I want to manually set the foo.bar variable through the JavascriptExecutor but cannot get a reference to the variable. How would I find then set the variable?
If that seems like the wrong way to trigger this ng-click, I am open to ideas. I am sure Protractor has a way to handle this but this AngularJS application deployed in an enterprise environment and have been trying to get the business side to approve the tech for months. I am stuck with Selenium. Help...
JSexecutor?