handling iframe with capybara ruby - ruby

Below is the html code ..
<iframe id="I0_1366100881331" frameborder="0" width="100%">
<div class="ZRa">
<span id="button" class="hAa Qo Bg" tabindex="0" role="button" title="" aria- label="Click here to publicly +1 this." aria-pressed="false">
</div>
</iframe>
In the above scenario, I want to switch into the IFRAME (iframe id="I0_1366100881331") to perform some actions on the SPAN present in that IFRAME. I have tried with most of the cases but no result :(... any one please help.
I want the solution for cucumber using capybara ruby only..
Note: I tried with following code but no result.
page.driver.browser.switch_to.frame "I0_1366100881331"

within_frame(find('<css rule>')) do
<code for dealing with iframe entries>
end

I think you can try to use method:
within_frame 'id' do
<code for dealing with iframe entries>
end

Can have this code:
withinframe((:xpath,"//div")) do
#code
end

Related

Dynamic xpath using anchor tag

Can any please help me in finding the dynamic xapth?
I have tried with,
#FindBy(xpath="//a[contains(#href,’friend#/friends/myfriends/friendsrequest’)]")
public WebElement lnk_FrndsSeeAll;
Here is the HTMl code,
<a class="pull-right see" href="friend#/friends/myfriends/friendsrequest">See all</a>
you can following xpath, which I'm taking using text in the anchor tag
//a[contains(text(),'See all')]
See all should be constant always, then only above xpath will work
It was working fine with beloew code,
#FindBy(xpath="//a[startswith(#href,'friend#/friends/myfriends/friendsrequest')]‌​‌​")
<a class="pull-right see" href="friend#/friends/myfriends/friendsrequest">See all</a>
<a class="pull-right see" href="friend#/friends/myfriends/friendsrequest">See all</a>

How to simulate click in span using Mechanize Ruby?

I have a webpage with list of pages:
<div class="pager">
<span class="current_page">1</span>
<span class="page" samo:page="2">2</span>
<span class="page" samo:page="3">3</span>
<span class="page" samo:page="4">4</span>
<span class="page" samo:page="5">5</span>
<span class="page" samo:page="6">6</span>
<span class="page" samo:page="7">7</span>
<span class="page" samo:page="8">8</span>
<span class="page" samo:page="9">9</span>
<span class="page" samo:page="10">10</span>
<span class="page" samo:page="11">11</span>
</div>
How can I click on the span using mechanize?
According to this ASCIIcasts you can perform searches and findings:
There are two methods on the page object that we can use to extract
elements from a page using Nokogiri. The first of these is called at
and will return a single element that matches a selector.
agent.page.at(".edit_item")
The second method is search. This is similar, but returns an array of
all of the elements that match.
agent.page.search(".edit_item")
http://asciicasts.com/episodes/191-mechanize
So doing something like:
agent.page.at(".page")
Will return the array of spans. And then you will be able to work with them and just do the #click action.
EDITED:
As long as the span is a non interactive element, and click is a Link action, you will have to find a workaround:
How to click link in Mechanize and Nokogiri?

Using ruby and selenium webdriver how I can get class from "container"?

I have the following form:
<div id="PaymentInfoDivContainer" class="checkout-section-container complete">
<div class="checkout-section">
<h3 class="sheen">
<span class="step">2</span>
Payment Information
</h3>
<a class="sc-button-white edit-button" onclick="SC.Checkout.Edit(this);"
href="javascript:;">Edit</a>
<div class="checkout-section-content">
</div>
Using Ruby and selenium webdriver, how I can get (and click) on "edit-button" class ?
As I understand I have to get and store in variable id="PaymentInfoDivContainer" and then use it to find the right class. Any thoughts/ideas?
Thanks
Okay,You can go as below : CSS3 [attribute$=value] Selector
driver.find_element(:css,'a[class$="edit-button"]').click
or
driver.find_element(:css,'div#PaymentInfoDivContainer>div>a').click

How to stop auto-refresh onclick from thumbnails?

I have an image gallery on my site that uses thumbnails that enlarge above the thumbnail line when clicked on. I'm having an issue with the auto-refresh; every time I click one of the thumbnails, the page refreshes, which restores it to the "master image".
I'm not (and sort of refuse, on the grounds that I believe all this can be done with simple CSS and HTML) using anything fancy to write this code, despite my knowledge of HTML being amateur at best.
Here's a sample of the code. Let me know if you need to see a different piece of it.
<div id="rightcol">
<img name="ImageOnly. src='#' /><img src="#" />
</div>
<div id="leftcol"> <div>
<a href="" onclick="ImageOnly.src='#'"><img src="#" />
</div>
Edit: Somehow I seem to have fixed this issue by changing
<a href="" onclick="ImageOnly.src='#'">
to
<a href="#" onclick="ImageOnly.src='#'">
Not really sure why this worked but would love an explanation...?
Why not just use some simple ajax/javascript .innerHTML? instead of trying to stop the auto refresh that occurs when you click on a hyperlink that has #. That way you could update the rightcol synchroniously.
HTML
<div id="rightcol">
<img name="ImageOnly.src" src='#' />
</div>
<div id="leftcol">
<img src="#" />
</div>
AJAX Script
function ajaxMove(src)
{
var image = '<img src="'+src+'" alt="my transferred image" />';
document.getElementById('rightcol').innerHTML = image;
}
How is it used?
Request the object from the onclick event.
Build an image tag based off the information in the object.
Transfer the new image tag to the element with the id 'rightcol'
Other options
You could also remove the href="#" from the <a> tag and work directly from the onclick event and then apply style="cursor:pointer;". Then it will work like a regular hyperlink but without the refresh.
<a onclick="javascript:ajaxMove('ImageOnly.src')" style="cursor:pointer;" >Click Me</a>

Easier way to click button in nested divs with Watir?

I'm new to Watir and I'm trying to click the following login button:
<div class="container login" style="display: table;">
<div class="left">
<div class="right">
<div class="joinbox">
<form id="form_login" class="hidden-submit" method="post">
<input type="submit" value="Submit">
<div class="header">
<div class="left">
<div class="mid">
<div class="right">
<a class="button button-red submit" href="#">Log In</a>
...
So far I'm able to access this button by going through every nested div:
b.div(:class, "container login").div(:class, "right").div(:class, "joinbox")......
and so on. Is this really the best way to access this button? I assume I'm missing something. Any help is appreciated!
If there is only one link (that looks like a button) with text Log In on the page, try this:
browser.a(:text => "Log In").click
You could also use class attribute:
browser.a(:class => "button button-red submit").click
May this work?
browser.form(id,form_login).submit
BTW: I have seen some tips said safari only support GET mode for submit.
I would try:
browser.a(:href => "#").click
Assumption - "#" is unique. may need a slash so it doesn't misinterpret the #. I used something similar when I was trying to reference a button with only a href value of "/login" e.g., browser.a(:href => "/login").click.

Resources