0

So I'm automating some different things with Selenium WebDriver in one of our orgs.

One of the more tricky ones has been interacting with the Execute Anonymous window inside of the developer console. Lots of elements can be found and use .getText() and .click() within that window, but just about every approach I've tried to either .sendKeys(Keys.SOMEKEY + "anotherKey") or .clear() return back as non-interactive errors.

Is this by design as defensive programming in their security model, since it is after all an anonymous execution window?

My other alternative would be to wrap some DX commands into my code and do error handling that way, but am hoping someone can definitively answer here.

TIA!

  • 2
    What's the end goal here? Are you looking to run some code? You can also execute anonymous through the tooling api. – Kris Goncalves Dec 12 '19 at 22:54
  • I think that except if you work at salesforce, you have no reason to automate the developer console , there is probably an API allowing to do what you need ... but what do you need to do ? – Nicolas Vuillamy Dec 13 '19 at 10:17
  • Thanks for the replies. Yes, I'm trying to execute some Java that pulls in the Apex from text files. Use case is having an in-house app that executes TestNG tests ad hoc. We're automating a bunch of other things that aren't accessible via regular SF API's, so wanting to keep things Selenium based where applicable, this particular bit is just a short-term need so wanted to know if this is technically possible or not. – trebleCode Dec 13 '19 at 13:57
1

Selenium Action does the trick and can type to the console:

Actions actions = new Actions(webDriver);

By linesBy = By.xpath("//*[@class='CodeMirror-code']//pre/span");    
List<WebElement> lines = webDriver.findElements(linesBy);

while (lines.size() > 0) {//deleting old Apex code    
    lines.get(0).click();
    actions.sendKeys(lines.get(0),Keys.chord(Keys.CONTROL, "A")).click().perform();
    actions.sendKeys(Keys.BACK_SPACE).perform();
    lines = webDriver.findElements((linesBy));
}

actions.sendKeys("System.debug('Hello');\n").perform();
actions.sendKeys("System.debug('World');\n").perform();

WebElement buttonExecute = webDriver.findElement(By.xpath("//button//span[text()='Execute']"));
buttonExecute.click();
| improve this answer | |
  • Thank you @CyrilJusko ! – trebleCode Mar 13 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.