Switching control between multiple child popups - javascript

I have a parent window, it has only login fields, i have stored its control using:
String parentWindow= idriver.getWindowHandle();
when the login credentials are entered, a new popup(say "popup A") opens and my app runs in it.I have switched the control to this "popup A" using:
for (String handle1 : idriver.getWindowHandles()) {
idriver.switchTo().window(handle1);
}
Now, when i click a button in this popup A, a popup opens(say "Popup B"), i again used:
for (String handle1 : idriver.getWindowHandles()) {
idriver.switchTo().window(handle1);
}
and the control was transfered to this popup B.
The problem is now i want to swtich to a popup C but the code that worked for switching from parent window to Popup A and then from popup A to popup B is not working.
The control is left on popup B and does not get transfered to window C. Please help. I am using Java, selenium , Win 8, IE 10.

I think that in idriver.getWindowHandles() is your parent window... you need to exclude existed windows.
public String popupHandle(List<String> existingWindowHandles) {
String popupHandle = null;
Set<String> windowHandles = driver.getWindowHandles();
for (String handle : windowHandles) {
for (String existingWindowHandle : existingWindowHandles) {
if (!handle.equals(existingWindowHandle)) {
popupHandle = handle;
break;
}
}
}
return popupHandle;
}
using:
List<String> ignoreWindows = new ArrayList<String>();
String parentWindow = idriver.getWindowHandle();
ignoreWindows.add(parentWindow)
String popUpWindow = popupHandle(ignoreWindows);
idriver.switchTo().window(popUpWindow);
String currentWindow = idriver.getWindowHandle();
ignoreWindows.add(currentWindow);
// doing your code
// new popup appears
popUpWindow = popupHandle(ignoreWindows);
idriver.switchTo().window(popUpWindow);
I think this will help you, good luck.
P.S. i didn't try it sorry, i don't have near a hardware to try it.

i have used the following and it worked for me:
`String windowTitle = "Popup C";
Set<String> handles = idriver.getWindowHandles();
for (String window : handles) {
Thread.sleep(200);
idriver.switchTo().window(window);
Set<String> mhandles = idriver.getWindowHandles();
for (String mwindow : mhandles) {
idriver.switchTo().window(mwindow);
System.out.println("Im in");
Thread.sleep(200);
if (idriver.getTitle().contains(windowTitle)) {
idriver.switchTo().window(mwindow);
System.out.println(windowTitle);
break;
}
}
}`
if any one has a better suggestion, please feel free to add. thanks

Related

Problem with recaptcha3 for .NET MVC website

I'm quite new in web development, have only couple of weeks of experience.
Currently working on C# website and can't get ReCaptchaV3 to work.
I have a subscribe form that shows up as a modal when user clicks on a "subscribe" button on the bulletin page.
In the form I have hidden input field: <input type="hidden" name="Google-captcha-token" id="GoogleCaptchaToken">
It generates the token when "Sign Up" button of the form is clicked.
My problem is - how to I get a hold of that value on the backend in C#? and then send it to google for verification? I also need to check if value I got from Google is within needed range and everything is good continue submitting the form.
This is where I stuck. I understand that I need to catch that value and work with it in the controller, but don't know how to do that.
Hope someone can help me out on this one.
This is how the code in the controller looks
public class BulletinController : _SharedController {
public ActionResult Index(int p = 0) {
var perPage = 10;
if (p < 1) {
p = 1;
}
var starting = (p * perPage) - perPage;
if (starting < 0) {
starting = 0;
}
var token = HttpContext.Request.Form["Google-captcha-token"];
var ns = new NewsServices();
var newsArticles = ns.GetNewsArticles(starting, perPage);
var count = ns.GetNewsArticlesCount();
ViewBag.Paging = Pagination.Generate(count, starting, perPage);
return View(newsArticles);
}
public ActionResult Details(int id) {
var article = new NewsServices().GetNewsArticleByID(id);
if (article == null) {
return HttpNotFound();
}
return View(article);
}
}
I watched a lot of videos on how it should be done, but none of them worked.
It seems to be a problem that view of the page is already using a model and that model is autogenerated. So looks like I can't use another model. Current model is also a list model (not sure what that exactly means though).
The other thing is that submission of the form is not going through the back-end and done through the constantcontact JavaScript sign up script.
Hope somebody will be able to help. Thanks.

Hiding field of custom-multi-field using javascript in listener

I have customized form of multi-field in a component having two variations.
In one variation of my component I want to hide a field (title) which is inside custom-multi-field . I am using the following JavaScript code in listener.
This code is not working. Where am I wrong?
function() {
var dialog = this.findParentByType('dialog');
var contenttype = dialog.getField("./type").getValue();
var teaserlinks = dialog.getField("./teaserlinks");
var title = dialog.getField("./teaserlinks").getField("./title");
alert(title);
if(contenttype == 'variation-1'){
teaserlinks.show();
title.hide();
}
else if(contenttype == 'variation-2'){
teaserlinks.show();
}
}
Try using the hidden property of node. Initially set the hidden property to true and in javascript file change the hidden property to false (or as per your requirement).
Few imp points first before answer:
you have to write listener in your widget file only.
below is the sample code where in I have 2 fields. 1st field is mytext field and another field is myselection. On changing the value in myselection field I am toggling visibility of my text field.
Below is snippet:
this.mytext = new CQ.form.textField({...})
this.myselection = new CQ.form.Selection({
fieldLabel:"my selection",
type:"select",
width : "325",
allowBlank:false,
defaultType:"String[]",
fieldDescription : "Select value from dropdown",
options: "/a/b/c.json",
listeners : {
selectionchanged : function(){
var mytext = this.findParentByType('mywidget').mytext;
mytext.hide();
}
}
});
I hope this will be helpful.
I have no knowledge about aem and Adobe CQ5 but I can give you some hints how to debug your script.
First of all don't use alert for debugging! (BTW what does alert(title); show?)
I would recommend to open the browser console (e.g. Press <F12> on Firefox and switch to the tab "Console").
Herein the browser displays all exceptions and error messages. Additionally you can output some text with console.log("...");` from your script.
Here is my edit of your program. Perhaps the output can help you.
function()
{
var dialog = this.findParentByType('dialog');
var contenttype = dialog.getField("./type").getValue();
var teaserlinks = dialog.getField("./teaserlinks");
var title = dialog.getField("./teaserlinks").getField("./title");
console.dir(title);
console.log(contenttype);
teaserlinks.show();
if(contenttype == 'variation-1')
{
title.hide();
}
else if(contenttype == 'variation-2')
{
title.show();
}
}
And, console.dir(<object>); shows you the object structure to one level deep.

CKEDITOR 4.3 surrounding data with tags?

I'm using CKEDITOR in version 4.3 and got sections of a html as input.
Now i need to make sure, that the costum-data always got a root tag (in my case a div with the class='CKEDITOR-autoadd).
so when my input is:
<p>jkdhgjkhngvkh</p>
<p>shgnuvzv</p>
my output has to be
<div class='CKEDITOR-autoadd'>
<p>jkdhgjkhngvkh</p>
<p>shgnuvzv</p>
</div>
Does anyone got an idea how i could solve this?
I had the idea of adding a custom plugin like
if(!root-tag found){
add div
}
Summary 2 Problems:
1. How do I surround my custom-data with tags?
2. How do I check / search a root-tag?
regards Sebastian
Edit: the failure in the Java-Applikation happens when:
public Element addSection(String title, String xmlAsString, String lang) throws IOException, JDOMException {
Content content = null;
try {
SAXBuilder saxBuilder = new SAXBuilder();
StringReader reader = new StringReader(xmlAsString);
→ Document doc = saxBuilder.build(reader); ← ERROR = JDOMParseException
content = doc.getRootElement();
content.detach();
}catch (JDOMParseException jdomParseExc) {
content = new Text(xmlAsString);
}
return this.addSection(title, content, lang);
}

Print preview xulrunner

So I'm having this problem with opening print preview in xulrunner.
I open print preview but i can't get the navigation toolbar.
This is the code from PrintUtils.js where the toolbar is created:
var XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
printPreviewTB = document.createElementNS(XUL_NS, "toolbar");
printPreviewTB.setAttribute("PrintPreview", true);
printPreviewTB.id = "print-preview-toolbar";
printPreviewTB.className = "toolbar-primary";
And later it does this:
var navToolbox = this._callback.getNavToolb
navToolbox.parentNode.insertBefore(printPreviewTB, browser);
I'm providing the navToolbox, that's the place where the toolbar is inserted but it doesn't show. As I said, print preview opens perfectly, pages formatted and everything but without toolbar.
Anyone have any idea why?
Ok, i found soulution, if anyone is interested.
So when enternig printPreview you have to pass an object with 5 functions:
getSourceBrowser, getPrintPreviewBrowser, getNavToolbox, onEnter and onExit.
With getNavToolbox you pass the reference to toolbar (placeholder) where you want to place standard navigation toolbar (with print button, zoom, and others).
I have done all that but you have to bind to that toolbar, like this :
toolbar.style.MozBinding = url('chrome://global/content/printPreviewBindings.xml#printpreviewtoolbar')";
I'm doing that in the onEnter function.
But i also had problem with the enterPrintPreview function from PrintUtils.js.
In this part of code:
var printPreviewTB = document.getElementById("print-preview-toolbar");
if (printPreviewTB) {
printPreviewTB.updateToolbar();
tmptoolbar.updateToolbar();
var browser = this._callback.getPrintPreviewBrowser();
browser.collapsed = false;
browser.contentWindow.focus();
return;
}
printPreviewTB.updateToolbar(); throws error.
I fixed this by getting the reference to the toolbar that i passed in getNavToolbox function and then calling updateToolbar on him, like this:
var printPreviewTB = document.getElementById("print-preview-toolbar");
if (printPreviewTB) {
var tmptoolbar = this._callback.getNavToolbox();
tmptoolbar.updateToolbar();
var browser = this._callback.getPrintPreviewBrowser();
browser.collapsed = false;
browser.contentWindow.focus();
return;
}
And now everything works fine.

How to Display the Html content page wise using webview in android?

hi i create simple app to display html page in webview i use the webview and display the page load time like this.
After this Disable the scroll and use the next and previous button to back and forward contain.
So my code is below.
First onCreate display add webview and load the html file.
mainWebView = (WebView) findViewById(R.id.mainWebView);
mainWebView.setVerticalScrollBarEnabled(false);
mainWebView.setHorizontalScrollBarEnabled(false);
mainWebView.getSettings().setJavaScriptEnabled(true);
mainWebView.setWebViewClient(new MyWebClient());
mainWebView.setPictureListener(new MyPictureClass());
mainWebView.loadUrl("file:///android_asset/chapter-001.html");
after use the MyWebclient Class for get the Height and width for mainwebview.
class MyWebClient extends WebViewClient
{
#Override
public void onPageFinished(WebView view, String url)
{
System.err.println("Page Finish Call");
lanscapHeight = protraitHeight = findHeight = mainWebView.getHeight();
System.err.println("Find Height->"+findHeight);
System.err.println("Portait Height->"+protraitHeight);
System.err.println("Landscap Height->"+lanscapHeight);
}
}
after this use the myPictureClass to get the webView contain length.
class MyPictureClass implements PictureListener
{
#Override
public void onNewPicture(WebView view, Picture picture)
{
proTraitContain = mainWebView.getContentHeight();
System.err.println("picture Class Call-->"+proTraitContain);
}
}
after this.create button next and previous to display the next and previous page.so use the SimpleOnGestureListener to Detect touch event.
btnNext = (Button) findViewById(R.id.btnNext);
btnNext.setOnTouchListener(this);
btnPrev = (Button) findViewById(R.id.btnPrev);
btnPrev.setOnTouchListener(this);
Override touch Method.
#Override
public boolean onTouch(View view, MotionEvent event)
{
if (view == btnNext)
{
btnClickFlage = true;
gestureDetector.onTouchEvent(event);
} else
{
btnClickFlage = false;
gestureDetector.onTouchEvent(event);
}
return false;
}
implement the SimpleGestureListener class as Below.
class MyGesture extends SimpleOnGestureListener
{
#Override
public boolean onSingleTapUp(MotionEvent e)
{
super.onSingleTapUp(e);
System.err.println("Display Total Contain For Protrait -->"+proTraitContain);
System.err.println("Before Height-->" + findHeight);
if (btnClickFlage)
{
if (findHeight > (proTraitContain+protraitHeight))
{
if(restProtraitFlag)
{
System.err.println("If part In side Flag-->"+findHeight);
findHeight=findHeight+protraitHeight;
restProtraitFlag=false;
//findHeight=findHeight+protraitHeight;
mainWebView.scrollTo(0, findHeight);
System.err.println("If part In side Flag-->"+findHeight);
}else
{
mainWebView.loadUrl("file:///android_asset/chapter-002.html");
restProtraitFlag=true;
}
}
else
{
if(protraitFlag)
{
if(findHeight==protraitHeight)
{
findHeight = protraitHeight;
}else
{
findHeight = findHeight + protraitHeight;
}
protraitFlag=false;
}else
{
findHeight = findHeight + protraitHeight;
}
mainWebView.scrollTo(0, findHeight);
}
}
else
{
restProtraitFlag=true;
if (findHeight<=0)
{
mainWebView.loadUrl("file:///android_asset/chapter-001.html");
System.err.println("Load Previous page");
}
else
{
findHeight = findHeight - protraitHeight;
mainWebView.scrollTo(0, findHeight);
}
}
System.err.println("After Height-->" + findHeight);
}
return true;
}
}
but i can't Display the last page of current html page path.now what to do.any solution please give.it's urgent.
i get the content width properly and use the scrollTo method to display but i can't do it.after last page rest of some contain can't display.
Please saw me the any way.
Thank in advance..
Hi Friends Finally i got my question answer.i use the ScrollTo method to scroll the contain and Display next contain of current page.but problem is there webView Display all contain according device.so all time contain display is higher then this current value.so i use the Webview.getScale(); method to Display how much scale use by webview.according to this i use this method and get current contain of webview in and use Display page wise.its finally its work for me..
Name For CalenderOuthenticationDe
Hello You have to put your HTML in res and then in that you have to keep it in raw after then you can access it like this...
webviewTips.loadUrl("file:///android_res/raw/tips.html");
You are showing the web page stored in your assets folder or from sd card.
So, My advice is that leave this approach and this way to show the web page to user..
And Edit your HTML files and put Anchor Tags in that...using that the user can traverse through the web page easily. (Example for that)

Categories

Resources