Submit result of form ti iframe - forms

I have tried looking up a good and easy way of showing results in either a new window or iframe.
I have a html/Java solution, that are not optimal. It shows the checkbox value, regardless if it's checked or not.
What I like, is the example in section: Checkboxes vs Radio Buttons
at url: https://www.html.am/html-codes/forms/html-checkbox-code.cfm
What I was impressed of, is that it automatically add comma between choices, if more than 1 selected.
The html part is no problem, but I see it targets a cfm file.
How is this example possible?
Can someone show me the missing coding, to make this work?
I have tried and getting more and more frustrated, tried to make a iframe, but its blank, tried formatting with the variable, still no luck.
atm. I am using this example below.
If possible, could you provide me with all the needed code?
Thanks alot in advance.
Searched here as well as other sites.
Found many similar problems and solutions, but none that solves this one.
This problem still get on my nerves, as I cannot seem to find a proper solution.
Unfortunally, the site posted above, do not allow download of the example.
<input type="checkbox" name="check1" value="Choice 1">
<label>Choice no. 1?</label><br>
<label>Choice 1: <span id="f1"></span></label>
<script LANGUAGE="JavaScript" type="text/javascript">
function check()
{
document.getElementById("f51").innerHTML = document.myform.check1.value;
}
</script>
<p><input type = "submit" onclick="check (); return false"></p>
My solution shows the value, despite being selected or not.
I like a solution like on https://www.html.am/html-codes/forms/html-checkbox-code.cfm in section "Checkboxes vs Radio Buttons"
I hope you can provide me with the missing code, so I can get peace in my mind about this problem.
Thank you in advance.

Related

Xpath. Unable to select text of label - when another element like <input> is between the <label> tags

Java dev and new to Xpath. Googled and RTFM-ed quite a bit but stuck. Company has a large webapplication written in Java, using the Java Wicket framework. Using Selenium in combination with Cucumber and Junit for testing. Hence Lots of Xpath expressions are needed to be written. Stuck with the following.
A screen with a form and two toggles () and text behind it . Relevant snippet.
<label>
<input id="idf1" name="removeConditionViaTreeStep:resultsRadioGroup" value="radio3" checked="checked" type="radio">
Safe to delete
</label>
<label>
<input id="idf2" name="removeConditionViaTreeStep:resultsRadioGroup" value="radio4" type="radio">
Unsafe to delete
</label>
Note: Using the Wicket framework means that the attributes id and value are/can be different each time the application runs so can NOT use them. Can NOT change the html either.
Plan A
I wanted to select a specific toggle (and emulate clicking/selecting it) by using the label text as a uniq selector but the fact that between the tags there are .. gives me problems. In clean label situations I can select a certain label without problems.
Can't get things like //label[contains(text(),'Unsafe to delete')] to work in this case.
Gave up and went for plan B.
Using firepath addon for firebug for testing and came up with the following: //input[#name='removeConditionViaTreeStep:resultsRadioGroup']
This results in firepath in two matches. I hoped to use something like [2] to select the second toggle, but could not figure it out.
Plan C - resorting to Java and Xpath worked.
List elements = findElementsByXpath("//input[#name='removeConditionViaTreeStep:resultsRadioGroup']");
elements.get(1) // select second toggle.
Have this feeling "//label[contains(text(),'Unsafe to delete')]" does not work because everything is streamed and nothing is held in memory by the Webdriver of selenium. Hence the element breaks the stream or something like that......
Perhaps someone can give a few hints and pointers or even a solution for plan A and B.
Edit corrected the closing parenthesis typo as mentioned by Bill Hileman.
I know you said you can not change the HTML, but maybe you can run the application in wickets development mode on the test environment? This way, if I remember correctly, wicket:id should be rendered and you would have an easier time to select elements.
Your xpath attempt as you typed it is:
//label[contains(text(),'Unsafe to delete']
Unless that was a typo here only, you missed a closing parenthesis.
//label[contains(text(),'Unsafe to delete')]
That xpath should work.

Keystone.js - Displaying Blog Categories on Index Page

On my Blog and Post pages I am able to display the categories list by using:
{{# each data.post.categories }}
<div class="tag-cloud">
{{name}}
</div>
{{/each}}
However the same exact code on the index view does not do anything (no errors, this section just displays as empty when I run keystone).
Any tips?
Thanks!
You're probably missing the corresponding code in your routes.
If you look in routes/views/blog.js you'll find some code which sets locals.posts.categories, and this is then accessed as data.posts.categories in your view.
Try to replicate the necessary bits of this code in routes/views/index.js. It sounds like you don't need the actual posts, just the list of categories, so you'll only need some of the code from the blog route.
If you're still struggling I can give you more explicit code, but hopefully you should be able to figure it out on the blog.

Selenium findElement(s) issues when search for anchor tag

I have a few nav bar items that I am trying to find with driver.findElement(by.id("menu-news-menu-item")) and driver.findElements(by.id("menu-news-menu-item")). It can't find them for some reason. I have verified that the id is correct on the site but it still can't be found. I know there are other ways to get to the info, but it is my understanding that using the id is the best way to go about finding elements. Below I have included an HTML snippet of what I am trying to search for. If I need to provide any more information please let me know.
<div class="navbar-collapse collapse">
<li>
<a id="menu-news-menu-item" href="/novus/news">News</a>
</li>
</div>
From looking at your HTML I see one potential problem. There may be more.
The top level DIV you posted has a class navbar-collapse collapse. That indicates to me that that DIV is collapsible and is currently collapsed which means that any of its children will be hidden. Selenium was designed to allow the user to only interact with visible elements. This means that if you search for your A tag by ID and it's a child of the DIV that is currently collapsed, Selenium won't find it. What you need to do before you search for the A tag is to unhide it. I don't know for sure how to do this but it probably involves clicking the collapsible DIV.
With this info, try to figure the rest out on your own. You should be able to investigate the page HTML, try some code, and see what happens. If it doesn't work and you get stuck. Come back and post some more of the surrounding HTML, the code you tried, and the result (error messages, etc.) and we'll try to help you more.

Selenium Java - inspect element and page source shows different infiormation

i am trying to navigate through pages using selenium web driver and i am stuck at one point
please refer to the image where i have shown the output of inspect element for that page that i am working on.
but in the page source (which i saw on the browser and also using Jsoup) looks like this,
<html>
<head>
</head>
<frameset rows="75,60,*" resize="no" SCROLLING="NO" name=main border="0">
<frame src="/frame/topnewprof.shtml" name="top" SCROLLING=NO>
<frame src="/frame/blank.html" name="menu" SCROLLING=NO >
<frame src="/itrade/user/welcome.exe?action=chk_seckey_stat" name="body" SCROLLING=AUTO>
</frameset>
<body>
</BODY></html>
why is this mismatch? and the yellow stuff that i have highlight in the image above has the element that i need!!
how will i get there using selenium??
i know that we can navigate into the iframe using selenium's switchTo().frame() but even if i get into any of the three frames as shown above in the page source information, i'm not able to find the information i need,
can this be achieved ? is it even possible?
UPDATE:
hello guys! i found the solution to this and now that huddle is crossed.
actually what happened was , when i was trying to do getPageSource, selenium was actually getting the frame source of one of the frames ("body" - as mentioned above), i accidentally figured that out.
Next to solve my problem i wanted to come one step back from where i was so i can select this iframe = (name="top") which was the target where i had the content as shown in the image. to Achieve this i used Selenium's defaultContent() function and came back one step then with switchTO().frame() went into the frame of my desire and accomplished the task
hope this helps!!
and thanks for everyone who tried to help me on this.
I couldn't exactly tell you why this mismatch is caused but I have an idea of how you could solve this problem.
I had similar problems with javascript phrases on pages. Normally such elements have to be clicked to get into. But if this element isn't clickable or a click doesn't sole the problem you could also search the information you need by using unique Xpath's.
I'm not sure if you using Selenium IDE already but maybe you could record navigating to this element and use the thrown java code from the Selenium IDE to get the required Information.
... I only have seen this problem while using Selenium remote control not the Selenium WebDriver...
I think the problem could also be solved by using xpaths. The easiest way to get the correct xpath is using firebug with firefox. Right click on the element in developer tools and click copy xpath. Firebug's incredibly accurate when producing xpaths. It has solved many problems like that one for me.
*Even if you aren't using firefox, most of the time you can use the same xpath from firebug in chrome webdriver testing.
It's a life saver.
Warning though, sometimes the path is long like:
final static String planTitlePath = "/html/body/div[1]/div[2]/div[1]/div[2]/div[5]/div/div/div/div/section/div/div[2]/div/ol/li/div[1]/plan-card/h4/span";
i found the solution to this and now that huddle is crossed. actually what happened was , when i was trying to do getPageSource, selenium was actually getting the frame source of one of the frames ("body" - as mentioned above), i accidentally figured that out. Next to solve my problem i wanted to come one step back from where i was so i can select this iframe = (name="top") which was the target where i had the content as shown in the image. to Achieve this i used Selenium's defaultContent() function and came back one step then with switchTO().frame() went into the frame of my desire and accomplished the task
hope this helps!! and thanks for everyone who tried to help me on this.

Like button code doesn't work on my website

I found a few similar topics however none specific to my issue. I went to create a like button code, I clicked the create like box, added my link http://www.facebook.com/pages/SpartaPerformancecom/248083571902684 to the URL formated the like button how I want it to appear. Then I opened Dreamweaver and pasted the Facebook code in the Dreamweaver HTML code where I want the Like button to appear but I get nothing. Please respond like "coding for dummies" language so I can understand how to solve my issue. Thanks in advance.
Make sure you add <div id="fb-root"></div> somewhere between the <body></body> tags. Their latest like button generator is missing that part.

Resources