Create element in Selenium - javascript

I am using the Selenium plugin to test my javascript code. Part of my code is that, onclick anywhere on the document body, a div is created and placed there. It works fine when I click myself, but after the click action on a selenium test case, nothing is created and I'm left with an error. Is this some missing feature of selenium, or am I doing something wrong?
Here is a screenshot:

Related

Blocked elements by default ? - Cypress

i wanted to ask if there are web elements blocked by default? If yes is it possible to not block them anymore?
Im running a cypress test and after clicking a save button there has to be a messagebox(similar to an alert).
This messagebox is not showing up after clicking the button.
Did anyone have similiar experiences?
Some infos :
Browser used : Edge
messagebox has the div tag
messagebox is nested inside of an iframe
I tried to run the test with the minium amount of code to verify if not some kind of comparision blocked me. But thats not the case.
I also tried a cy.wait for a longer time to see if it loads up.
I also tried a cy.reload but still nothing.
When i do it manually on Edge everything is working fine. The messagebox is showing up after clicking the save button but when cypress runs the test it just isnt showing up.
When i click on the button manually inside the cypress testrunner it´s also NOT showing up.

Get xpath element in flexbox

If I click the chrome extension it open a window (flex) I can inspect it but I can't interact with it.
If I try its xpath and assert it , it always fails. I think I need to switch to it first then assert it. Like we for iframes.
Xpath I tried was "//button[text()='Merge']". Click on the image to see clearly.
How can I verify it? If not selenium can I assert it in JavaScript maybe? I don't know how do it in JS

Selenium IDE automation seems to break JavaScript window

I'm using selenium IDE (currently available only on firefox) to do some automated testing of a site I'm coding. When selenium navigates to, a form filling page, and fills in the info - a 'window.alert()' is called by a button.
When using selenium my set of commands look like this:
open /
clickAndWait document.form1.Action[1]
select stuff
type stuff
etc, etc
click name=myPreview
When I click through recording this the first time, it works no problem. When I rerun the script window.alert and alert don't work from the console or anything. I've debugged it, and its not working.
When a window.alert() is called as part of a selenium script (I'm talking at least in the IDE), it is called even though a user watching does not see an alert pop up. According to the documentation:
Under Selenium, JavaScript alerts will NOT pop up a visible alert
dialog.
Selenium does NOT support JavaScript alerts that are generated in a
page's onload() event handler. In this case a visible dialog WILL be
generated and Selenium will hang until someone manually clicks OK.
Both assertAlert and verifyAlert are both based off getAlert(), all of which do the alert 'stuff' in the background. So try adding these functions to ensure that the alert is working, run the script, and then check to see if it works.
A note: this only works if you ensure the test fails before you put in the alert (basic idea of testing, fail first - make test pass).

How to find JS code is working in browser?

I am using bootstrap modal, I dont know where I have put the js code that triggers the modal after clicking the button.
jQuery('#signin').modal('show');
I checked each file...even checked each JS file in source in browser.
How can I find which code is triggering the event in browser when I am clicking the button to open a modal?
Use a developer tool for a browser which will allow you to perform Javascript debugging. Your best bet is most likely Firebug. If you set a debug point at a line within a JS file, firebug will allow you to inspect the stack to see which line has called the function.
Instructions
In Firebug, click the script tab.
Select your .js file using the drop down.
When the JS file displays find the target line and click to the left of it, setting a debug point.
Load your page, the script should stop at your debug point.
Click the Stack tab on the right and inspect.
Searching for Script in Firebug
If you click the script tab you can enter a known piece of the script in the upper right hand corner of firebug, this should take you to its location in the code.
I agree with Kevin, another option is to print the stack trace using something like:
http://www.codeovertones.com/2011/08/how-to-print-stack-trace-anywhere-in.html

click not work on IE9 ruby webdriver

I'm using this code to click on an element: #driver.find_element(:id, "test").click and it works well when I run script on FF16 with Selenium Ruby Webdriver (selenium-webdriver-2.26.0.gem).
However, when trying to run script in IE9 browser (using IE driver: IEDriverServer.exe), no error occurs, but Click event does not work, Selenium seems to ignore this line of code and go to next lines of code.
Note that this issue does NOT happen when I tried to click on many other elements on my application (ex: button, link), it only happens with some elements I want to click.
Please help guide me how to resolve for Selenium to fire Click in IE9 browser. Thanks much.
Try click using JavaScriptExecutor or Click after moving to the element. refer below C# code
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].fireEvent('onclick');", element);
or
Actions action = new Actions(driver);
action.MoveToElement(element).Click().Build().Perform();
where element is IWebElement instance of element to click

Categories

Resources