window.stop() execution through selenium is not working - selenium

I am trying to read elements from the page using selenium but it seems the page is getting loaded infinitely. The element which I want to read is visible on the page (tried xpath and I was able to fetch the element). I tried the below code to execute the javascript command to stop the page load but for some reasons it is getting time out.
driver.executeScript("window.stop());

As #pcalkins suggested to use PageLoadStrategy, I used the "none" strategy in the chrome capabilities and it really did work. Below is the chrome capability property which I set.
"pageLoadStrategy" : none

Related

Getting "Nosuch element Exception" in Selenium Though XPATH is correct. Not sure is this due to Shadow DOM. Please confirm

I am trying to automate Salesforce application Using Selenium and getting NoSuchelementException though XPATH is correct and valid for particular object. When i have searched the issue, it might be reason for Shadow DOM.
For EX:
So XAPTH i have written like,
driver.findElement(By.xpath("//input[#name='Name']")).sendKeys("Jams");
or
driver.findElement(By.xpath("//input[#id='input-299']")).sendKeys("Jams");
This XPATH is highlighting in Console as well. But while automating it throws nosuchelement error.
So while checking for ShadowDOM option, am getting option like this for Name Object.
#shadow-root(user-agent)
Shadowroot DIV
-- nothing mentioned in div. it just open and closed tags.
How to automate this?
You can check if there are any iframes in your Dom. Simply do //iframe in your page developer mode(F12)> elements tab > search (Ctrf+F) area. If there are any, you will get the number of iframes.
Now if your textbox is in any of iframe use below code to go inside particular iframe first
driver.switch_to.frame("<name or Id of frame>")
then come out to frame use below:
driver.switch_to.parent_frame()
Also, if the issue is not related to frames check below for shadow-root related issue:
you can check below for shadow-root element ( Question is for Java, but you can co-relate):
How to interact with the elements within #shadow-root (open) while Clearing Browsing Data of Chrome Browser using cssSelector
The website contents are mostly created now using javascript. You may have to wait for certain elements to load before doing anything to it.
https://seleniumbyexamples.github.io/wait

Robot Framework - Locating input element with accept attribute fails

I am writing an automation script for an avatar upload module with the following CSS locator:
input[accept="image/png,image/jpeg,image/gif,image/bmp"]
I am using Robot Framework's Wait Until Element Is Visible keyword to look for the locator above but is unsuccessful with the error:
Element 'css=input[accept="image/png,image/jpeg,image/gif,image/bmp"]' not visible after 30 seconds.
Increasing the timeout also doesn't work. Using the same in Chrome Dev Tools would successfully find the element. My guess is that the commas/slashes are messing with Robot's locator parsing. My question is: What is the correct way to write the locator?
Though present in the DOM, an element may not be visible/rendered. This is very often the case with file upload input elements - the UI renders something different, a button, div that had applied styling and fits in better with the overall design.
Thus a check is it visible will rightfully fail. Change your pre-usage approach to validate the input is in the HTML - this is actually the same as what you did in the browser's dev tools - with the Page Should Contain Element keyword, and proceed on success.
There is no problem with the CSS locator your are using. Maybe the element is in another iframe?

"Cannot locate an element using By.xpath" error in selenium java

I am getting Cannot locate an element using By.xpath error in Selenium using Java(IE11). I am working on a web page created using Adobe AEM(CQ5).
I have tried the following possible solutions but neither of it helped.
Tried to add wait.
Switch to active window.
Tried even on Chrome.
Bring focus on element.
Currently using the absolute path (/html/body/div[4]/header[1]/div[1]/div[2]/div[5]/div[1]/nav/ul[1]/li[3]/a) but also used relative path (.//*[#id='cq-gen188']/nav/ul/li[3]/a).
Also searched whether there is any iframe involved. Unfortunately there was none.
To find the xpath, I have used FirePath plugin in Firefox. When i search for the element using the xpath in Firefox, i am successful. But when i execute the code i get the error.
If you are in the correct IFRAME then you can use
driver.findElement(By.id("cq-gen188"));
Remember that ID is always unique and that's a core assumption for all of the libraries in the authoring UI whether it is from core AEM framework or from custom components.
Your problem may be due to incorrect IFRAME as AEM neatly makes the UI look like a seamless window but there are IFRAME in place to facilitate various authoring navigation experiences.

Selenium evaluates DOM or Visible elements

I would like to understand how Selenium evaluates the page.
I have set of test to check elements on the page. Written with Nunit, Selenium and PhantomJS as Driver.
Page.Visit();
Page.FindElement(By.Id("testid").Text.Should().NotBeNull(); // PASS
Page.FindElement(By.Id("testid").Text.Should().NotBeEmpty(); // does NOT PASS
The test DOES NOT pass if the browser size is set to be very small:
driver.Manage().Window.Size = new Size(10,10);
Based on this test, it is confusing how PhantomJS evaluates the page. I always thought that it checks the DOM but seems like for element TEXT it evaluates based on visibility!
Although this surprised me too when I first discovered it, Selenium will only find elements visible in the viewport of the browser. For this reason, you will want to ensure at the start of your tests that your browser viewport is large enough to accommodate the content of your application.
Typically this can be done by maximizing the browser window. If you are using Windows, triggering the F11 key via Selenium should work.

Selenium Script Fails even though Xpath , Firebug show the correct element

I had a question . When i "inspect" this particular element and take "exact" xpath and copy it to my selenium script and run my script, it fails to identify?
Any idea how to do it?
Repeating again, i copied the exact xpath , tried inspecting element. All correct. Still :(
Thanks,
S.K
If Selenium fails to find an element you know is present, commonly the problem is with synchronization: Selenium tries to access the element too fast, before it appears on the page (and when you try to inspect element even a second later, you can see it, since it was rendered by then). Try to WAIT for the very same element before doing anything else. Examples of the wait can be found here