rails Nokogiri click all buttons with same tag - ruby-on-rails

I am trying to scrap a web page that requires a click in order to display a phone number (https://homestars.com/on/toronto/electricians?page=1).
I can access and click on the 1st button using
browser.button(class: "company-search-contact__button").click
But I can't acess the following ones given that they all have the same tag.
I have not found any variations of the button() method that can be more specific.

The expression you are using would only click on first button. You need to select all buttons and click them one by one
page = Nokogiri::HTML(open("https://homestars.com/on/toronto/electricians?page=1"))
buttons = page.css('button.company-search-contact__button') #select all buttons on the page
buttons.each do |button| # for each button
button.click #click on the button
end

Related

Adding multiple dropdown on clicking a link

I have a link which says "add another field". On clicking the link a dropdown should appear on top with let's say 5 custom fields as list in dropdown. Once user selects a field in that dropdown and clicks hyperlink another dropdown should appear below existing dropdown and with only 4 remaining fields as one is already selected.so how to start this?
https://tutorialslink.com/Articles/How-to-add-control-dynamically-in-Aspnet-MVC-using-Javascript/64 . I have tried to use this link which adds text boxes to get started.
I don't have any code expect for the code in above link which is for text box though. Just need an idea of how to do it in asp.net MvC as i cannot move forward now.
Expected results is to do the above requirement, don't have any actual results as of now

How do I create a lightbox in AppDrag?

I would like to have a Youtube video play in lightbox format. Is there a way to achieve that using the AppDrag CMS editor?
First create a new page in your project.
Keep the page format as a landing page, removing thus the header/footer.
in the new page, click on the "+" button on the left then click on ELEMENTS > Medias and Drag a youtube element into the blank section and remove the placeholder text there.
Right click on the section containing the video, click on SECTION > Edit > Position and there check the "full height" checkbox.
Go back to your original page.
Open the button you would like to use to trigger the video, and select the Link tab.
Scroll to Website Page -> select the page you have created earlier.
Then a bit lower, still in the Link tab, select "Open in -> Modal".

Capybara + Poltergeist + Phantomjs. Unable to click a button

i have a button, upon clicking it will change the display of a div from none to block. I wanted to click on the button, have the div displayed as 'block', click "Done" and then the div's display become 'none'. Capybara was able to click on the 1st button but it couldn't seem to find the 2nd button "Done". I tried several ways:
click_on("Done")
find_button("Done").trigger('click')
find_button("Done").trigger('click')
find_link("Done").trigger('click')
I even tried to use javascript:
page.execute_script("document.getElementById('button_done').click()")
but nothing happens. I printed out the display property of the pop-up div prior to the clicking "Done" and after the clicking to check if the button was click but both statements gave me the div's property as 'block' (expected 'block' before clicking "Done" and changed to "none" after the clicking).
I allowed it to sleep(10) but doesn't seem to help.
I used the same javascript on the page console and it worked as it should be.
Any inputs?
Thanks
EDIT:
feature:
Given I click on "Create an item"
And I chose an option
Then I should be able to create an item
steps:
step "I chose an option" do
within ('#web') do
click_on "On"
end
sleep 3
#Here is where the div gets displayed with the 'Done' button
find('#button_done').click #(doesn't work though)
sleep 3
click('Create')
end
try find('selector', :visible=>false)

jQuery Mobile NavBar with back button of previous page

On an iPhone when you have a NavBar at the top, there is a back button.
Rather than say "Back" it has the title of the previous page in it.
So you might be on say the "Checkout" page. The title of the NavBar would be "Checkout" and the button might say "Books".
Clicking on the button that says "Books" takes you back to the previous page.
How can this be accomplished in jQuery mobile without the need to code in the name of the back button as you may have gotten to that page from a different route?
edit
I know I can do this on the page;
<div data-role="page" id="pageViewChallenges" data-add-back-btn="true" data-back-btn-text="previous">
But that makes the buttons text "previous" instead of the name of the page.
U can use
Books
(If u r using external page)
and
Books
(When using Internal page)
This is simple settings to customise back button and if u want previous page title as back button then simply get the title of back button through jquery method and set in the back button title.IF u can get the previous page title then set it on pageshow event by getting the id of back button using jquery like this:
$('#MaterialAndQuantityDetails')
.live(
'pagebeforeshow',
function() {
// page header Management
$('#bkbtnid').html("");
$('#bkbtnid').html(BackButtontext);
});
And if u r thinking how to get the title of previous page then on previous "pagehide" write the code
var BackButtontext = document.getElementById('previous_page_header_id').value;
Here BackButtontext is global variable that is to be used to set the back button text.

How to know which radio button is selected on a view?

I have a created a list view for one of my controller's index action.
I have added a new column "Select This" to this list view, by using the view's source.
The column will contain radio button for each entry in the list. This i have achieved by just placing a radio button control from tool box in the "Select This" column. This i have done in the design of the view and when i run it, i get radio buttons, one for each of the entry. The page also has a link button and i want to call a controller action on this link button click which will receive the index of radio button selected. So if i select 5th radio button, how can receive 5 in the controller action.
How can i do this?
Regards,
kapil
If you used plain HTML, your radio buttons will all have the same name, but different value. You will get one result in the POST, which will contain the selected value.
If you used ASP.net helpers, it's the same, but they will be generated for you: see here: http://msdn.microsoft.com/en-us/library/dd410596.aspx You will pass the same name (first parameter) and different values for each input (second parameter).

Resources