As part of a script I'm creating I am required click elements with a certain text value (exact case). To establish if I need to click anymore I intended to scroll to the bottom and as the page dynamically adds elements I wanted to use the below identify if any new element had appeared:
jQuery("button[rel='follow-button']").filter(function () { return jQuery(this).text() === 'Follow' }).length
Note jQuery is setup the same way as this answer: Get element with jquery and selenium IDE 1.0.8
However, whenever I try to store this value using the Selenium IDE (needed so I can loop the logic with the help of the Sideflow extension. It does not work as I had hoped.
I have found that this will work:
javascript{window.innerHeight}
This will generate a value not just return the variable name again when using Echo.
However whenever I replace this expression with my jQuery one above I get the following error in my Selenium IDE log:
[error] Unexpected Exception: Error: Permission denied to access property Symbol("Symbol.toStringTag").
Due to business requirements I must use the Selenium IDE, so any advise or tips to get around this issue would be much appreciated, as I don't have much experience with it yet and typically use Selenium Webdriver in C#
Related
I am trying to validate the contents of a readonly, disabled input field inside an iframe using Selenium IDE 2.9.1.
Since I am running the test suites on this HTML runner, I can only use the capabilities offered by Selenium IDE, meaning JS functions.
I tried to execute this document.getElementsByTagName('iframe')[2].contentWindow.document.getElementsByClassName('input').value in the devtools console and it worked, but not when using getEval or storeEval.
Results of the IDE are always null, or, if I add [0] to the input, the result is undefined.
Help would be really appreciated.
I tried to manipulate the divs on facebook.com using the javascript console to see if it was possible. I noticed there was a class called "profileLink", so I typed the following into my console:
$(".profileLink").hide();
But instead of the class being hidden, I got the following error in my console:
Error: <![EX[["Tried to get element with id of \"%s\" but it is not present on the page.",".profileLink"]]]>
But the method I tried works to manipulate other, lower-budget webpages. How did facebook accomplish this?
I'm pretty sure Facebook isn't preventing you, but the $ is not associated with jQuery.
$ isn't a built in to browsers, but usually is an alias for jQuery.
I'm trying to get MonkeyTalk working with Javascript. I'm automating some tests with iOS. When I run the .MT version, the test runs fine. But, the Javascript version errors with this.
ERROR sun.org.mozilla.javascript.internal.EcmaError: TypeError: Cannot find function uISearchBarTextField. (RADialerDirectory.js#8) in RADialerDirectory.js at line number 8
The export javascript code shows this:
this.app.uISearchBarTextField().tap();
Anyone know how to get around this error? I'm just trying to use the Javascript version of the script to loop and later grab external data to iterate through.
I had the same problem for "UIAleartView". There are three ways to get it work. this happen because MonkeyTalkAPI.js file doesn't contain an entry for "uISearchBarTextField"
Use more generic type(Input) like above answer.
Set accessibilityLabel property of that component and use it as a monkeyID like here: MonkeyTalk : Verify custom UITableViewCell Label text without select the cell
A little hack to MonkeyTalkAPI.js class. find the word for "Input" which is more generic to your "uISearchBarTextField" and get a copy of it paste it again in that file and edit replaceing "Input" with "uISearchBarTextField" save it and run. if you did it carefully it works.
Happy Testting
I'd like to write a test case (using Selenium, but not the point of this question) to validate that my web application has no script errors\warnings or unhanded exceptions at certain points in time (like after initializing a major library).
This information can easily be seen in the debug consoles of most browsers. Is it possible to execute a javascript statement to get this information programatically?
It's okay if it's different for each browser, I can deal with that.
not so far read about your issue (as far as I understood your problem) here
The idea be the following:
I found, however, that I was often getting JavaScript errors when the page first loaded (because I was working on the JS and was introducing errors), so I was looking for a quick way to add an assert to my test to check whether any JS errors occurred. After some Googling I came to the conclusion that there is nothing built into Selenium to support this, but there are a number of hacks that can be used to accomplish it. I'm going to describe one of them here. Let me state again, for the record, that this is pretty hacky. I'd love to hear from others who may have better solutions.
I simply add a script to my page that will catch any JS errors by intercepting the window.onerror event:
<script type="text/javascript">
window.onerror=function(msg){
$("body").attr("JSError",msg);
}
</script>
This will cause an attribute called JSError with a value corresponding to the JavaScript error message to be added to the body tag of my document if a JavaScript error occurs. Note that I'm using jQuery to do this, so this specific example won't work if jQuery fails to load. Then, in my Selenium test, I just use the command assertElementNotPresent with a target of //body[#JSError]. Now, if any JavaScript errors occur on the page my test will fail and I'll know I have to address them first. If, for some strange reason, I want to check for a particular JavaScript error, I could use the assertElementPresent command with a target of //body[#JSError='the error message'].
Hope this fresh idea helps you :)
try {
//code
} catch(exception) {
//send ajax request: exception.message, exception.stack, etc.
}
More info - MDN Documentation
I am a Selenium newbie ...
As a JavaScript programmer, I think I want to handle JavaScript events in my Selenium-2 tests (JUnit). I am joining a team where all of the existing tests have "waitForSomethingToBeRendered" methods. Is there some way my Selenium tests can handle/listen for DOM (or custom) events?
Also, I've read on SO where developers use FireBug to write/debug Selenium-2 tests. How does this work? I don't see FireBug in the browser launched by Selenium. Similarly, why does the following appear to have no effect? Am I trying something Selenium/JUnit does not support?
selenium().getEval("alert('hello');");
selenium().getEval("debugger;");
You don't see the firebug extension because selenium opens a stripped firefox. I'm guessing the reason is it's much faster. It's possible (and quite easy in selenium-2) to add the plugin.
The alert doesn't work because selenium-1 (I don't know how selenium-2 handles them) swallows the alerts. There's an api for handling alerts.
Plus, in selenium-1, the JS runs in a different window. So the equivalent of document.getElementById() is sel.getEval("selenium.browserbot.getCurrentWindow().document.getElementById()").
Finally, I don't know about events but you can wait for conditions: sel.wait_for_condition().
Firstly if you are getting started with Selenium I suggest using the 2.0 API which is for WebDriver. To evaluate JavaScript in 2.0 simply cast your WebDriver object to a JavascriptExecutor object and use the methods provided by it. 'waitForSomethingToBeRendered' needs to be done in a few steps. First of all you must ensure the DOM object is available on the page. For this you can do something like this:
WebElement e = null;
try {
e = driver.findElement( By.id("asdf") );
} catch {
...
}
Or:
driver.findElements( By.id("asdf") ).size() != 0
After determining whether the DOM object is available you can do:
e.isDisplayed()
Which will return to you whether the element is currently displayed.
In regards to what you have seen about FireBug and Selenium I am guessing you are confusing Selenium IDE which is a Firefox plugin with Selenium RC/WebDriver which is not a plugin.
Use Firebug for Firefox while normally browsing your site to explore your DOM to determine the correct element and class ids to select in your Selenium script. If you are using extjs you are going to have some extra fun in determining which elements to select, as extjs randomizes element ids. The best way is to add an extra css class to find the correct element, then select by that class.