I have a switch / toggle element coming from bootstrap. It works perfectly as expected but I'm having trouble when testing the feature because I don't know how I can click on it:
the toggle is handled by the pseudo-elements :before & :after. I tried many pieces of code to simulate the click on it with capybara but I didn't find a way to achieve it...
Here the snippet: https://jsfiddle.net/ynuf96qe/
Anyone has an idea? Thank you!
Sorry for this element, I didn't find a way to bypass the link error from stackoverflow...
<div></div>
I finally found a way out even if I don't like it...
I changed the way the toggle is displayed in test environment: it is a simple checkbox that allows me to click on it through Capybara.
It now works fine but I'm aware that is a hack.
Related
I've been struggling with trying to automate this page. After I login, I'm at this page where I'm supposed to click a button before I redirects me to the next page. The problem is that this button does not have a name or an ID which is making it very difficult to find this element. I've tried mechanize and splinter both. And finally tried selenium but that didn't help either. Really struggling with this. Just need to click this damn button! Any help would be really really appreciated. Love python and automation, but this time nothing seems to be working for me. Please find below a snapshot showing the the code shown when I click on "inspect element". Also, I can't type here the page source code as it is >300000 characters, so you can probably take a look at the page (you'll need to login which takes just 10 seconds). The page I'm referring to is right after you login - http://www.160by2.com/Index
[!Snapshot showing the code I get when I click "inspect element"
[]1
There is class name:
driver.findElement(By.className("da-sms-btn").
Also you can open application in Chrome and copy CSS or XPATH in browser:
Open application in Chrome
Inspect element
Right click on highlighted area
Copy CSS or XPATH
You can try first getting the form by the id, then getting the button by the class name:
wd.find_element_by_id("frmDashboard").find_element_by_class_name("da-sms-btn").click()
You can try to find the element through its xpath. Selenium does a good job of this:
webdriver.find_element_by_xpath("element xpath").click()
You can easily find the xpath by going to the inspect element sidebar on Chrome and right clicking on the element you want. The right click drop down menu should have an option "copy xpath".
I would write a cssSelector as follows and try that.
button[onclick*='aSMS']
Notice, I am doing a partial search with *
Thank you so much for your replies! I was actually able to make it work using splinter instead of selenium! Here's what I did-
1) I just executed the js which was being executed on the onclick event of the button.
jsstring="window.parent.openPage('SendSMS?id="+id+"', 'aSendSMS', 'aSMS', 'ulSMS')"
br.execute_script(jsstring)
2) Subsequently, I was faced with the problem that on the next page, everything was embedded inside iframe, and so find_by_name and all were not able to find elements. For that, splinter provides a nice method (Which is documented REALLY bad, so had to figure it out myself with help from stackoverflow)
with br.get_iframe('iframe_Name') as iframe:
iframe.fill("Element_to_fill_Name","Text_to_fill")
iframe.find_by_tag("TagName")[Index_number].fill("Text_To_Fill")
Worked out brilliantly! Thanks everyone :)
I am having problems with triggering RaphaelJS's Element.click() with jquery. What I am trying to do is simulating with jquery that the Element.node was clicked and what I am expecting is that Raphael will delegate the click treatment to the previously defined Element.click() method.
In some circumstances I will need to trigger Raphael's Elements event handlers with code somehow using my Element instance.
In order to simplify my problem, I created a plnkr with just the code that does not work for me. So here is the example:
http://plnkr.co/edit/AuSuq1RG6cWpqH2GEzcN?p=preview
What I expect of the code is that after $(r.getById("square").node).trigger("click"); (I have also tried using $(r.getById("square").node).click()) is executed, myRectangle.click(function() {...} will be called and the heading on the result page will be changed to "The rectangle was clicked!". As you can see this does not happen. However clicking on the shape is working fine.
Does anyone know what do I miss in this small piece of code? How to make such manipulation work?
Thanks!
After I worked around my initial problem so I can finish what I did start, now I found a helpful kinda-solution to the problem that might help others that come across my topic. What is written in the topic works and worth considering to be adopted as solution. It do look a bit hacky, but to be honest many things in JS do so. So here is the link, hope it can be helpful to someone someday :) - Triggering Raphael events externally
i am trying to do selenium automation for a web page but XPath is not working for elements in grid\spans\telerik controls. I have used all possible scenarios to get the element's xpath.
I want to click on the highlighted area 'Reports'. Please guide me.
So far I have tried:
//*[#id="SidebarMenu_ulOverallMenu"]/li[13]/a
/html/body/form/div[3]/div[3]/div[1]/div/ul/li[13]/a
install firebug and firepath plugin in firefox.
You can view the xpath by using them.
Just Try By.linkText("REPORTS")
This happened many times. You made a small mistake. May be that div is not shown on the screen. So try this
driver.findElement(By.id("Sidebar")).click();
or
driver.findElement(By.id("SidebarMenu_pnlOverAll")).click();
Then
driver.findElement(By.xpath("[#id="SidebarMenu_ulOverallMenu"]/li[13]/a")).click();
or
driver.findElement(By.xpath("/html/body/form/div[3]/div[3]/div[1]/div/ul/li[13]/a")).click();
I was searching for some custom checkboxes made with jQuery and i run into http://damirfoy.com/iCheck/ plugin. It seems perfect and it acts perfect on web, but there is a little issue on ipad and iphone.
Problem: when i click on a checkbox, something is blinking (ins element) and it look very bad. I need it to work like it's working on the web. Can anybody help please?
Ps. Usually i search for other solutions, but this plugin really seems great besides that problem, it has lots of functions and i really want to use it.
Update: you can test it directly on any checkbox from this page : http://damirfoy.com/iCheck/ from an ipad or iphone. One thing that i found out now is that i see that background appear and disapear quickly on any element not only on checkboxes, on texts to.
-webkit-tap-highlight-color: transparent
will solve your problem.
I'm troubleshooting a scrolling gallery with standard left and right navigation arrows. I'm wondering if there is a way to track when a specific div or class tag is modified upon loading the webpage. My problem is that
<class="next browse right disabled">
is being applied to my right arrow when it should be
<class="next browse right">
It is a heavily modified jquery-tools scrolling gallery that someone else wrote and I'm just not sure how to approach this. Any advice/help is appreciated!
Jquery does not have any baked in event that can help you intercept addition/ removal of a class to div. You can at anytime use jQuery hasClass to see whether a particular class is applied or not.
$('#mySelector').hasClass('right') //returns a boolean
You can take advantage of chrome dev tools breakpoint debugging if you are performing these actions via javascript.
Finally, if you insist on capturing class change, then you must raise your own event. Please see this question:
jQuery - Fire event if CSS class changed
I'm not sure if this works:
$('next.browse.right.disabled').removeClass('disabled');
or
$('next.browse.right').removeAttr('disabled');
Maybe DOM Breakpoints in the Chrome devtools would help?