I am new in Selenium IDE. I try to select a PDF that opens during the test, but it doesn't work. I'am testing a Webapplication that is written on JSF and so includes some Java-Methodes/Classes.
I want to test if the PDF opens correctly or not. The problem is, there is no direct href in the HTML-Code. Only a Java(?)-Methode who opens the PDF. Is there any solution for this problem in Selenium IDE?
The Element you can click on is
<h:commandLink id="createDokument" style="background-image: none;" styleClass="Button Blue"
action="#{myBean.checkDocument()}" value="#{buttons['BTN_Document']}">
</h:commandLink>
Then a javaScript function should test if a pdf can be created
IF yes the hidden button is clicked:
<h:commandLink id="createDocumentPdf" style="background-image: none; display: none;"
styleClass="Button Blue"action="#{myBean.createDocument()}" value="something" target="_blank">
</h:commandLink>
What Firebug knows from this two buttons is:
<a id="mainForm:createDocumentPdf" class="Button Blue" onclick="if(typeof jsfcljs == 'function'){jsfcljs
(document.getElementById('mainForm'),{'mainForm:createDocumentPdf':'mainForm:createDocumentPdf'},'_blank');}return false"
style="background-image: none; display: none;" href="#">Something </a>
<a id="mainForm:createDocument" class="Button Blue" onclick="if(typeof jsfcljs =='function'){jsfcljs
(document.getElementById('mainForm') {'mainForm:createDocument':'mainForm:createDocument'},'');return false
"style="background-image:none;" href="#" tabindex="0">Document</a>
I tried a few things already but nothing works....
I tried: select window | titleOfThePDFWindow
but it does not work
so all I have now is:
clickAndWait | id=mainForm:createDocument
Related
I am trying to navigate a dropdown button that operates via JavaScript. However, no matter what I try, the HTML list items it should have never seem to show up in selenium.
An image of the dropdown button:
Inspector page source:
<div class="dropdown" style="border-bottom: 1px solid #ebebeb; padding-bottom: 2px;">
<a class="btn btn-default btn-sm" onclick="$(this).parent().toggleClass('open')" title="Select an Event" style="width: 220px">
<span id="event-selection-span-id">No event selected.</span>
<span class="fa fa-caret-down routing-toolbar-menu"></span>
</a>
<ul class="dropdown-menu user-dropdown dropdown-menu-left" id="call-events-list-id">
<li title="ADRC Archived Call" event_definition_id="2f617fc5-c0b0-492a-92e2-561c39c239fc" form_code="AACOG_ADRC_CCC_ARCH" onclick="CallCenter.SetEvent(this)" class="list-group-item event-group-list-item">ADRC Archived Call</li>
<li title="ADRC Information Call" event_definition_id="0a22deba-4788-4647-bee6-47305e182eca" form_code="AACOG_ADRC_CCC" onclick="CallCenter.SetEvent(this)" class="list-group-item event-group-list-item">ADRC Information Call</li>
</ul>
</div>
Selenium page source:
<div class="dropdown open" style="border-bottom: 1px solid #ebebeb; padding-bottom: 2px;">
<a class="btn btn-default btn-sm" onclick="$(this).parent().toggleClass('open')" title="Select an Event" style="width: 220px">
<span id="event-selection-span-id">No event selected.</span>
<span class="fa fa-caret-down routing-toolbar-menu"></span>
</a>
<ul class="dropdown-menu user-dropdown dropdown-menu-left" id="call-events-list-id"></ul>
</div>
Here is what I've tried so far, all unsuccessful:
Originally just tried finding the elements and using the .click() method to click in them. (e.g. driver.find_element_by_xpath('//*[#id="step-3"]/div[2]/a').click() then driver.find_element_by_xpath('//*[#id="call-events-list-id"]/li[2]').click(). Selenium could not find the list element in the second line.
Then I tried a method that's worked for me before when the previous one didn't: finding the elements then using driver.execute_script("arguments[0].click()", btn) for each one. Like before, it worked for the main dropdown button but not the list item that should show up afterwords.
So I figured I could just execute the javascript manually with the elements' JS paths using driver.execute_script("$(document.querySelector('#step-3 > div.dropdown > a')).parent().toggleClass('open');") then driver.execute_script("CallCenter.SetEvent(document.querySelector('#call-events-list-id > li:nth-child(2)'));"). This still didn't work and the list elements still did not show up in selenium's page source.
The strangest thing is the list elements show up in the inspector before you even click the main dropdown button. Therefore I should just be able to execute the second JS line manually with no problems, and that works fine when I do it in the browser. I have also tried just waiting for the list elements to show up when the source is loaded but they never show up no matter how long I set the delay for.
First to click on the element with text as Select an Event and then from the dropdown to click on the element with title as ADRC Information you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.btn.btn-default.btn-sm[title='Select an Event']"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.btn.btn-default.btn-sm[title='Select an Event'] +ul#call-events-list-id li[title='ADRC Information Call']"))).click()
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[#class='btn btn-default btn-sm' and #title='Select an Event']"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[#class='btn btn-default btn-sm' and #title='Select an Event']//following::ul[#id='call-events-list-id']//li[#title='ADRC Information Call']"))).click()
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
I have a normal link button where I am getting data through like this
<a href="ViewRemarks.aspx?jobid=<%#DataBinder.Eval(Container.DataItem,"jobid")
%>" id="btn_remarks" data-toggle="modal" data-target="#exampleModalCenter3"
class="open-AddBookDialog btn btn-outline-info " ><i class="fa fa-comments" ></i>
</a>
Note: in this button, I am getting data called job id
Then I took one bootstrap modal inside that modal I kept one child page like this
<iframe style="width: 470px; height: 195px;" id="Iframe1" class="embed-responsive embed-responsive-16by9" src="ViewRemarks.aspx?jobid=null"></iframe>
Note: iframe is not showing in stackoverflow don't know why but yes that is an iframe so i kept one a before iframe.
But here I want to pass that particular jobid from that button inside the data table how can I solve this in asp.net or javascript anything is accepted please help.
So use the link target which will load the link in the iframe.
<iframe name="iframe1" id="iframe1" />
and the link
My LInk
<iframe name="iframe1" id="iframe1"></iframe>
My LInk
I used Colorbox in my aspx project and I used the Iframe from example 1. I copied the css and js files mentioned in the html page but when clicking on the link, it opens up the page in the browser itself whereas I want it to show up in the box like in the examples.
Here's the code -
<a class='iframe' href="#" onclick="$.colorbox({href:'http://wikipedia.com', iframe:true, width:'90%', height:'90%'});">Click here</a>
You need to render the colorbox in an element on the page:
<a class='iframe' href="#" onclick="$('#container').colorbox({href:'http://wikipedia.com', iframe:true, width:'90%', height:'90%'});">Click here</a>
<div id="container"></div>
You must instead do this -
Click me
<iframe id="frame1" src="your_default_src"></iframe>
So I have a button with code like this:
<div style="text-indent: 0pt; visibility: inherit;" id="button5061">
<a title="Continue" href="javascript:if(%20button5061.hasOnUp%20)%20button5061.onUp()" name="button5061anc">
<img width="82" height="25" border="0" style="cursor: pointer;" alt="Continue" src="images/continueoff.gif" name="button5061Img">
</a>
</div>
And I need to click it with javascript. Right now I am using the firefox extension Chickenfoot which allows me to script the site with a javascript interpreter with some custom commands.
http://groups.csail.mit.edu/uid/chickenfoot/api.html
I have tried selecting it with xPath (//div/a[#title='Continue']/..) which finds it, but when I click() it nothing happens.
Here are some of the things I have tried:
click(find(new XPath("//img[#alt='Continue']/..")))
click(find(new XPath("//img[#alt='Continue']/../..")))
click("continue")
click("Continue")
click("images/continueoff.gif")
click("continueoff.gif")
click(find("Continue"))
click(find("Continue").element)
click(find("images/continueoff.gif"))
I know this is a rather specific quesiton but any ideas on what to try would be much appreciated.
html:
<div>
<a href="#" onclick="alert('ok')">
<img src="">
</a>
</div>
javascript:
var xPathRes = document.evaluate ('//div[1]/a[1]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
xPathRes.singleNodeValue.click();
jsfiddle:
https://jsfiddle.net/7fm89aqd/
If you're trying to simulate a user clicking on it:
You can simulate a click like this: document.getElementById('theSubmitButton').click();
Here's an example for ya: http://jsfiddle.net/gasWZ/1/
If that's not what you're trying to do, could you explain a bit more?
Wouldn't it be effective to pass the anchor object to your function and evaluate the name attribute?
set the href attribute to #
call the function and pass the obj
<div style="text-indent: 0pt; visibility: inherit;" id="button____"> <a title="Continue" href="#" name="button____anc"> <img width="82" height="25" border="0" style="cursor: pointer;" alt="Continue" src="images/continueoff.gif" name="button____Img"> </a> </div>
So here is a little challenge. I have an image. It has 2 attributes:
a random ID - not helpful
an image url - but it is a button, and other buttons use the same image url, not helpful
a CSS class - also used by too many other things to be helpful
a style - neither helpful nor unique
This image is however inside of an anchor tag, but the anchor tab isn't to a page, it just runs some javascript. Bellow is the html in question:
<a id="template:j_id__ctru168pc2"
title="Click for the Manual Class LOV" class="xei" style="text-decoration: none;"
onclick="return false;" href="#">
<img id="template:j_id__ctru169pc2" class="xgs"
style="border: 0pt none;" src="images/lov_ena.png">
</a>
How can I click this image without using the ID?
selenium.click("//a[#title='Click for the Manual Class LOV']/img");