Clicking JavaScript in Ruby/Watir - javascript

Is there ANY way to click a JavaScript link using the Watir webdriver? I've looked around for hours and nothing has helped me.
Here's what the link looks like: MULTIPLY YOUR BTC
I've tried using browser.link(:id, "double_your_btc_link2").click and a bunch of other stuff including Xpath (it kept saying it couldn't follow the path) and nothing works. Is it even possible?
If you need the page, here it is.

That should have been:
browser.link(:id => "double_your_btc_link2").click

Sorry to waste your time, guys. I just used Firefox instead of Chrome and it worked fine. This isn't even the first time I've had a problem with accessing JavaScript elements in Chrome...thanks anyway.

Related

Opening an about: link in firefox

Okay, so, I've been feeling like pulling my hair out on this one. I'm making my own homepage for school use, so I can easily and quickly do things.
I've hit a brick wall: You can't open "about:" links for whatever reason. Not using regular href="about:(target)", not using window.open("about:(target)","_self");. Any other links work fine, but as soon as I change it to about:, nothing happens. At all. Might as well not have pressed it.
If anybody has any solutions, that's be greatly appreciated. They don't have to be cross-browser compatible, because I'm only using firefox. If the information is needed, I use Firefox 18 (I may update it next week).
Did you try to use window.location.assign?
link

Toggle multiple div elements

On my page I'm currently doing something like this: http://jsfiddle.net/FBCSt/6/ I really don't know why, but in Chrome I got some strange issues with that - sometimes the contents of the div elements are not loaded correctly. In IE, Safari and Firefox it work fine, but as I said, in Chrome it is causing some trouble.
That's why I want to know, if there is a more sleek way to do this? (There are three buttons, every one is assigned to one div. Only one div should be visible)
I am thankful for every answer =)
EDIT: Thanks everybody. This is the solution. It works well =)
"a better way: jsfiddle.net/FBCSt/13 – #Mohammed ElSayed 20 mins ago"
Try this: http://jsfiddle.net/FBCSt/10/
In IE, Safari and Firefox it work fine, but as I said, in Chrome it is
causing some trouble.
I really don't see an issues when testing under Google Chrome 19.0.1084. But in any case,
That's why I want to know, if there is a more sleek way to do this?
Yep, there is. Since one of your tags is jQuery, I suggest you take a look at jQuery UI's tabs.
Why don't you use show() instead of toggle()? Maybe the issue is related to using toggle(). And you can combine the elements to be hidden: For example,
$('#page2,#page3').hide();
$('#page1').show();
Or as nicely put by Mohammad,
$('#page1').show().siblings().hide();
I have working solution on this url : pastebin it works in chrome and also in FF.also it will work even if you add 1000 id with page#100 but still it will not have too much code. thanks.
Like Abody97 said: try JQuery UI tabs
If you're looking for a "more sleek" way of doing this, try this fiddle: http://jsfiddle.net/NCbW6/
It doesn't bother with specific ids for each element so you can add as many as you'd like without changing the JS.

How to Click on link which has Javascript using Watir

I am new to Watir and have a scenario which is a blocker for me. I have to click on the below link. It is shown as a link. It is any normal forgot passord?? click here .... option which is there in the application which I am testing. Please advice how to click on this link. I have tried the below mentioned x paths as well but no luck.
<a href="javascript:forgot_password()">
x paths used with no luck :
1> ie.link(:xpath, "//img[#onclick='javascript:forgot_password()']").click
2> ie.link(:xpath,"//a[#href='javascript:forgot_password()']/").text # => "Click Here) "
3> ie.element_by_xpath("//link[contains(#href , 'javascript:forgot_password()')]/").click
Did you try this?
browser.link(:href => "javascript:forgot_password()").click
First check if xpath works on your system: appart form watir gem you have to have installed REXML with version greater than 3.1.6.
And i don't know what could be wrong with your code because I don't know which page you are accessing, if you can, please give us the link. Personally I would do something like this, but there may be lots of alternatives.
ie.link(:xpath, "//a[contains(#href='javascript:forgot_password')]/").click
Your xpath selectors look quite confused looking at them.
Line one
ie.link(:xpath, "//img[#onclick='javascript:forgot_password()']").click
intends to find a link, but looks for an image. Would that ever work?
Try using
ie.link(:xpath, "//a[#onclick='javascript:forgot_password()']").click
or
ie.link(:xpath, "//a[#onclick='javascript:forgot_password()']").fire_event('onclick')
It's potentially just not triggering the onClick event when using .click on an element. I can't remember whether it does or not.
Without seeing the page, I can't really be certain, but you might not need to be using xpath to find this element at all.
If the text is "Click here" you could use that as the locator instead.
ie.link(:text => "Click here").click
... or the equivalent .fire_event('onclick')
It's incredibly tough to diagnose the problem without seeing the html in question, and accurate Watir being run against it (i.e. copied and pasted directly from your file), so these suggestions are pretty much shots in the dark.

Adding Bookmarklet Javascript to Block?

Hello i've been trying to do this for about 2 years. I think it worked once but ever since then i just can't make it happen again. Im adding this code to a block-
<a href="javascript:u=document.location.href;t=document.title; s=window.getSelection();
void(window.open("http://onlinebanter.com/node/add/web2ob?edit[title]="+escape(t)+'&edit[body_field][body]='+escape(s)+'&edit[field_link][0][url]='+escape(u),'_blank','width=600,height=500,status=yes,resizable=yes,scrollbars=yes'));">Test</a>
When i try to drag that to my browser the url comes out as so-
javascript:u=document.location.href;t=document.title;s=window.getSelection();void(window.open(
I am using the Full HTML filter option and isnt adding line breaks or anything. If i edit the link in my browser and add just
javascript:u=document.location.href;t=document.title;s=window.getSelection();void(window.open("http://onlinebanter.com/node/add/web2ob?edit[title]="+escape(t)+'&edit[body_field][body]='+escape(s)+'&edit[field_link][0][url]='+escape(u),'_blank','width=600,height=500,status=yes,resizable=yes,scrollbars=yes'));
Things work great. I have looked about and have asked here previously
http://drupal.org/node/235074
I must just be missing something so simple as it seems the whole internet doesnt have this problem. All help appreciated thanks.
Reg`
I think the problem is with the double-quotes in your window.open() call.
The browser thinks that you're closing the href="javascript... "
Replace the double quotes in "http://onlinebanter.com/node/add/web2ob?edit[title]=" with single quotes.

Chrome problems

I have a few annoying problems.
The thing is, that when I am looking with Firefox every thing work perfect, after I try it with Chrome, sometimes happens that the code appears one web page (it is not all the time).
So, it appears in input text it display " />" or some piece of code of java script, which is written inside input tag.
The web page is: www.kalahoo.eu (do not try it in English )
In this picture you can see the problem:
http://rhc.si/slike/problem.png
Thank you very much for you help!!!
Can you post a link to the exact page with this error?
Either way, I would imagine that if you use the Chrome developer tools, you should get pointed in the right direction. Might want to give that a try.
You seem to be improperly escaping code that's making the HTML end before the rest of the attributes are read.
Check the spot in the code where its doing that, its probably a bad ' or " or even a >.

Categories

Resources