Why does Selenium ExecuteScript method doesn't work anymore in Salesforce application but ExecuteAsyncScript works - selenium

Hi I've been trying to figure this for the past couple of days. I wrote the code below that use to work but doesn't work any more using the ExecuteScript method. The only thing i have changed was update my chrome driver because it was not launching chrome since the driver wasn't working with the older chrome version I have. So once I updated the chrome driver it began to work until i had to run this piece of code. I modified it below not to what the actual link text is.
IJavaScriptExecutor js = (IJavaScriptExecutor)WebActions.One;
js.ExecuteScript("alert('Welcome to Guru99');"); // This was added for testing purpose
IWebElement somelink = WebActions.One.FindElement(By.XPath("//span[text()='Some Text']"));
js.ExecuteScript("arguments[0].click();", somelink );
When i changed the method to be ExecuteAsyncScript it started working again. Is this something that has changed with the app or is this something i'm doing wrong. I tried reading up on ExecuteAsyncScript vs ExecuteScript to see the difference but all i was able to get was something about the call back telling
when its finished which i'm not experienced in java script.
I would just like to understand more then anything or should i just start using ExecuteAsyncScript method. Thanks

There's a chromedriver ticket about this issue here:
https://bugs.chromium.org/p/chromedriver/issues/detail?id=3103
It states:
The cause of the issue is this website modifies the constructor of the
built-in AsyncFunction object. This causes difficulty when
ChromeDriver tries to create an AsyncFunction to wrap the script being
executed.
chromedriver 78 fixes the issue. For testing with Chrome 77, the ticket recommends switching to executeAsyncScript, or using chromedriver 76 since "ChromeDriver vX will run with Chrome vX+1".

Related

Selenium click() not working for microsoftEdge webdriver

I've tried the standard
var elementForMs = driver.findElement(By.xpath(selector));
driver.executeScript("arguments[0].click()", elementForMs);
and
var elementForMs = driver.findElement(By.css(selector));
driver.executeScript("arguments[0].click()", elementForMs);
And there are simply cases where the element never responds to the click in Microsoft Edge 15.01563.
Each driver has unique bugs. So somethings that work in Firefox, may not work in Chrome or so on. So the only way around is to find what works and use it. And if possible report the issue to the driver owner
In your case since finding the element and clicking on it doesn't work with
var elementForMs = driver.findElement(By.xpath(selector));
driver.executeScript("arguments[0].click()", elementForMs);
But works when you use javascript directly in console. that means you should execute the same in your code
driver.executeScript("document.getElementXXX().click()");

JavaScript Error: e is null popup during Selenium Test

I have test which is resulting in a Firefox pop-up which looks like this:
The exception is an InvalidOperationException and it goes on to say
JavaScript Error: "e is null" then making reference to a JavaScript file called commandprocessor.js
I am using the 2.44.0 version of WebDriver with Firefox version 33.
Out of completeness, I will also add that this pop-up is not throw on if a user manually follows the steps in that test.
Any ideas what is going on? Previous SO questions with similar error have yielded no answer.
Could be an issue with the driver itself. Have you looked at these issues logged with selenium webdriver?
Issue 7977: Upredictable javascript errors "e is null"
Issue 8095: fxdriver.error.toJSON fails to match qualified method names containing $
Based on the rev logs these fixes seemed to have been added after 2.44.0 release so they may not have made it yet to a release version.
In one of the callbacks, the code included
$('#confirmRegistration').attr('href', 'javascript:location.reload();');
Seems to be forcing a page reload, which the WebDriver did not like.

Element not being added when running test through webdriver

I am working on writing a story for a bdd framework which uses jbehave/selenium/webdriver and am having a problem where the test encounters an error while running the story but appears to be fine when running manually. I'm having a problem where javascript for the functionality I'm testing behaves slightly different when I'm running tests manually on firefox vs through selenium web driver on the same system/version of firefox and this difference is causing a js error.
I've debugged and basically the root of the problem appears to be that var request_XML_container = $('div_appendpoint_id'); returns something different when I'm running the test manually vs when I run through the bdd framework.
var request_XML_container = $('div_appendpoint_id');
request_XML_container.innerHTML = encoded_xml_from_request;
var pos = method_to_get_position('id_of_place_div_should_be_appended_to');
// JS exception is thrown saying that style is not defined **ONLY**
// when running through web driver. Running test manually on
// same system and same browser works fine.
request_XML_container.style.left = (pos[0] - 300) + 'px';
request_XML_container.style.top = (pos[1] + 25) + 'px';
request_XML_container.style.display = "block";
Why this would work fine when running manually that var request_XML_container = $('div_appendpoint_id'); would return an item with style defined, but when running through webdriver that the style attribute of the element would not be defined?
UPDATE: I had originally thought that this was updating an iframe, but I read the markup wrong and the iframe I saw is a sibling - not a parent - of the element where the response is being appended to. I'm trying to simply append the response to a div. To be honest, this only makes things more confusing as grabbing a div by id should be pretty straight forward and I'm now sure why webdriver would be producing a different return element in this situation.
UPDATE 2: Steps to reproduce and information about the system I'm on:
Use webdriver to navigate to this url: http://fiddle.jshell.net/C3VB5/11/show/
Have webdriver click the button. It should not work
Run your test again, but pause put a breakpoint at your code to click the driver
Click the button on the browser that webdriver opened. It should not work
Refresh the browser page on the browser that webdriver opened. Now, it should work.
System details:
OS : OS X 10.8.5 (12F37)
IDE : Eclipse Kepler: Build id: 20130614-0229
Browser (used manually and by webdriver) : Firefox 23.0.1
Selenium version: 2.35.0
UPDATE 3: I have provided this maven project on github to aid in reproducing: https://github.com/dkwestbr/WebdriverBug/tree/master/Webdriver
Synopsis/tl:dr; Basically, in certain situations it appears as though webdriver is overwriting the '$()' javascript method with a method that does not return an HTMLElement with innerHTML or style defined (among other things). This post details the issue and how to reproduce.
I have opened this ticket to track the issue: https://code.google.com/p/selenium/issues/detail?id=6287&thanks=6287&ts=1379519170
I have confirmed that this is a bug with the Thucydides framework (understandable since they still aren't at a 1.0 release).
Issue can be tracked here: https://java.net/jira/browse/THUCYDIDES-203

issues in running selenium in internet explorer

Hi I am trying to run my selenium webdriver on IE9.
WebDriver version : 2.32.0
IE:9
IEDriverServer_win32:2.32.3
windows7
Below is my code:
File IEDriver=new File(System.getProperty("user.dir")+File.separator+"BrowserDrivers"+File.separator+"IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", IEDriver.getAbsolutePath());
DesiredCapabilities cap=DesiredCapabilities.internetExplorer();
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
WebDriver driver=new InternetExplorerDriver(cap);
driver.get("http://in00616:8421/GS");
Thread.sleep(3000);
//driver.findElement(By.id("j_username")).sendKeys("admin");
//driver.findElement(By.id("j_password")).sendKeys("admin");
driver.findElement(By.xpath(".//input[#id='j_username']")).sendKeys("admin");
driver.findElement(By.xpath(".//input[#id='j_password']")).sendKeys("admin");
driver.findElement(By.id("login")).submit();
Thread.sleep(2000);
driver.findElement(By.xpath(".//button[text()='Securities']")).click();
Thread.sleep(2000);
driver.findElement(By.xpath(".//span[text()='Issue']")).click();
Thread.sleep(2000);
driver.findElement(By.id("tabSecurities_Issue_Request_for_Issues")).click();
Above code logs in to my site but then when I try to click on Securities button I am not able to do it. Securities button starts flickering and then I am notified that unable to find the element.
Exception in thread "main" org.openqa.selenium.NoSuchElementException:
Unable to find element with xpath == .//span[text()='Issue Type']
(WARNING: The server did not provide any stacktrace information) –
Same code works fine in FireFox.
Please help as i am suppose to test my UI on InternetExplorer.
I think it is the version compatibility issue.
Can anyone suggest the compatible version set for IEDriverServer, Selenium WebDriver and IE which is in working condition.
As this SO answer points out, IE does not have native XPath support. Instead, Selenium WebDriver uses an old third party xpath library when IE is being used. Firefox has integrated support for XPath, which is why your selectors work fine in that browser.
I would highly recommend you update your selectors to instead use CSS selectors. They are supported across all browser, are easier to read, understand, and pick up, and they are pretty fast.
You can learn more about how to use CSS selectors from some different tuturials here, here, and here, and a CSS selectors cheatsheet.
Also, whenever possible, please try to not select an element by the text it contains. If you can select an element by its ID, class, other attribute, or even through the DOM chain (i.e. "div.1 > div.2 > span.a > a.b"), is better than trying to select an element by text.
Webdriver has difficulty with IE using locators. It seems like Murnal has difficulty using CSS locator. My advice would be you HAVE to use other locators if one doesnt work. This issue comes again and again while using non firefox browser. In the meantime an easier way to come up with alternate locator is use Firefox selenium IDE, there in the boxes where you type command you will see it gives alternate locator as well. Copy that and try plugging tha in your webdriver's findelement script.
Hi all i have found out that it was the issue of Selenium Webdriver 2.32 with IEDriver_Server2_32. After trying out permutation & Combination with latest available webdriver versions and IEDriver_Server, i have found out suitable stable configuration to work on IE9 below is the stable configuration : Webdriver : 2.33.0 IEDriver_Server : 2.33.0. There is still small issue but i am trying to look for workaround. Issue : In IE if some control's tooltip overlaps other control than IE is not able to find out that control. i guess this issue is with IEs working. IE uses nativeEvents to perform operation hence it is not able to locate that control. In FF it is able to find out that control and it is working fine. Thanks everyone.

In Selenium, does ClickAndHold work with webdriver and chrome?

I'm trying to make a click-and-drag event work using Selenium Webdriver (2.15). It works fine when using FF, but in Chrome it does not. In Chrome, it appears to have no effect. Here's what my code looks like:
Actions builder = new Actions(GuiOps.driver);
builder.MoveToElement(fromElem).ClickAndHold().MoveToElement(toElem).Release().Build().Perform();
Has anyone gotten ClickAndHold() to work successfully using Chrome?
Turns out this is a known issue. There's a workaround posted at http://code.google.com/p/chromium/issues/detail?id=92312 . Basically, you add a MoveByOffset(1,1) immediately after that ClickAndHold() call and it works.
First post/comment here. :)
Well, it worked for me. All you need to give is a bit of a pause after the "moveByOffset(1, 1)". It seems that the script is executing faster than it should. Here's a piece of code that worked for me:
"actions.clickAndHold(we).moveByOffset(1, 1).pause(1000).perform();". Hope it helps.