After switching to new window, only 'urlContains' is working.
Nothing else is happening(neither click nor elementVisible or anything)
Partial code of nightwatch:
'Order Module' : function(browser) {
browser
.useXpath()
.waitForElementVisible("#OrderTab", 20000)
.pause(5000)
.click("#OrderTab")
.pause(5000)
.useCss()
.waitForElementVisible("input[title = 'New']", 20000)
.click("input[title = 'New']")
.useXpath()
.waitForElementVisible("#OrderTextBox']", 20000)
.verify.urlContains('https://invoiceit-s.na30.visual.force.com/apex/createJobStep1?retURL=%2Fa0K%2Fo&save_new=1&sfdc.override=1')
.setValue("#OrderTextBox", "Order Name")
.pause(10000)
.click("#LinkIconForNewWindow")
.pause(10000)
.window_handles(function(result) {
this.verify.equal(result.value.length, 2, '2 windows should be open')
var handle = result.value[1]
this.switchWindow(handle)
this.verify.urlContains('https://invoiceit-s.na30.visual.force.com/_ui/common/data/LookupPage?lkfm=j_id0%3AjobForm&lknm=j_id0%3AjobForm%3Apb%3Arender%3Aj_id38%3A0%3Aj_id39&lktp=001&lksrch=')
this.useXpath()
this.waitForElementVisible("#searchBox", 20000)
})
.pause(20000)
.end() }
i am not familiar with Xpath,Can you post the screen-print of the element block? May be i can help you
PS:Dont use too much pause(), it will slow down your test program,nightwatch will check element every 500ms.
Edit 1 :The problem may be because of '#searchBox' element,is this in the first tab of your browser after you clicked Pop-up Button ? If yes, it should be like:
.window_handles(function(result) {
var home = result.value[0], // your first tab
handle = result.value[1]; // second tab
this
.switchWindow(handle)
.verify.urlContains('https://invoiceit')
.useXpath()
.switchWindow(home) // you need to switch back to first tab , even you close the pop-up.
.waitForElementVisible("#searchBox", 20000)
})
PS:my answer from this post may help.Loop is not working properly - nightwatch
Related
In Wix, I have a text field in a repeater that is used for navigating to other dynamic pages. The link works, but there are two problems with that. First, I have to click two times, not double click, for functioning the link. Second, I want to make the text field act as a button link, I mean be able to right click on that and choose 'open in new tab'. How can I fix these problems in my code?
Here is the code
// Navigating to related dynaic page
import wixLocation from 'wix-location';
export function ndText_click(event) {
$w("#repeater1").onItemReady(($item, itemData, index) => {
$item("#nText").onClick((event) => {
let postTypeValue = itemData.pType
wixData.query("Collection1").eq("_id", itemData._id)
.find()
.then(results => {
let item = results.items[0];
let pIDValue = item.postId;
if (postTypeValue == "R") {
wixLocation.to('/re/' + postIDValue);
} else if (postTypeValue == "L") {
wixLocation.to('/lo/' + postIDValue);
}
})
});
})
}
I suggest trying to use a button instead of the text element. You can usually style the button so it looks the same as the text element you already have. Then instead of setting the onClick, try setting the button's link and target properties.
I want to click on an element, but I don't know why, before clicking on that element the hover appears. What I need is that if this hover appears, avoid it, such as pressing the ESC key, or if you know any other way.
Here is my code:
await browser.wait(EC.elementToBeClickable(element.all(by.className('center-align short-label white mf-show-type-episode')).first()), waitLongTime);
var elements_master = await element.all(by.className('center-align short-label white mf-show-type-episode'));
await elements_master[0].click();
var row_selected = browser.element(by.className('ui-grid-row ng-scope ui-grid-row-selected')).element(by.className('field-link ng-binding'));
await browser.sleep(500);
if(await tooltip.isDisplayed() == true) {
await tooltip.sendKeys(protractor.Key.ESCAPE);
await row_selected.click();
} else {
await row_selected.click();
}
It gives me an error that the tooltip is not interactable.
you can use javscript click described here
var loginButton = element(by.css('.login-form .login-button'));
browser.executeScript("arguments[0].click();", loginButton);
you can also call it "forced" click, because what it does is - it clicks on the element regardless its visibility. And even if there is another element on top of it, it will click the element you pass
I've created a basic extension that searches Google if the URL/HTML content fulfill certain requirements. It works for the most part, but fails miserably when there are multiple instances of the extension. For example, if I load tab A and then tab B, but click on the page action for tab A, I will be directed to a search of tab B's content.
I don't know how to silo the script to each tab, so that clicking tab A's page action will always result in a search for tab A stuff. How can that be done? I'd appreciate your suggestions!
background.js
title = "";
luckySearchURL = "http://www.google.com/search?btnI=I%27m+Feeling+Lucky&ie=UTF-8&oe=UTF-8&q=";
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.title != "") {
title = request.title;
sendResponse({confirm: "WE GOT IT."});
}
});
chrome.tabs.onUpdated.addListener(function(tabId, change, tab) {
if (change.status === "complete" && title !== "") {
chrome.pageAction.show(tabId);
}
});
chrome.pageAction.onClicked.addListener(function(tab) {
chrome.tabs.create({url: luckySearchURL + title})
})
contentscript.js
function getSearchContent() {
url = document.URL;
if (url.indexOf("example.com/") > -1)
return "example";
}
if (window === top) {
content = getSearchContent();
if (content !== null) {
chrome.runtime.sendMessage({title: content}, function(response) {
console.log(response.confirm); })
};
}
You could do something like store the title with its associated tabId, that way when you click on the pageAction it uses the correct title. The changes would be just these:
background.js
title= [];
[...]
chrome.runtime.onMessage.addListener(function(request,sender,sendResponse){
if (request.title != "") {
title.push({tabId:sender.tab.id, title:request.title});
sendResponse({confirm: "WE GOT IT."});
}
});
[...]
chrome.pageAction.onClicked.addListener(function(tab) {
title.forEach(function(v,i,a){
if(v.tabId == tab.id){
chrome.tabs.create({url: luckySearchURL + v.title});
// Here I am going to remove it from the array because otherwise the
// array would grow without bounds, but it would be better to remove
// it when the tab is closed so that you can use the pageAction more
// than once.
a.splice(i,1);
}
});
});
You're facing this issue because of window === top. So your title variable gets its value from the last opened tab. So if B is opened after A, title gets its value from B. Try this: Detect Tab Id which called the script, fetch the url of that tab, which then becomes your title variable. As below:
chrome.pageAction.onClicked.addListener(function(tab) {
chrome.tabs.query({active:true},function(tabs){
//this function gets tabs details of the active tab, the tab that clicked the pageAction
var urltab = tabs[0].url;
//get the url of the tab that called this script - in your case, tab A or B.
chrome.tabs.create({url: urltab + title});
});
});
My extension should open a popup window (a normal popup window, not default extensions popup) with a following conditions:
only one window could be opened in the moment,
I want to save window size and position in localStorage, and restore them on next open.
How to do so?
I tried:
chrome.browserAction.onClicked.addListener(function() {
// 1. In this case, variable win is a window object. But it's empty. There
// is no properties/methods to operate with.
var win = window.open('http://example.com','windowname');
chrome.windows.create({
'url': 'http://example.com',
'type': 'popup'
}, function(win) {
// 2. In this case, variable win has some properties, but they are static
// and won't change on window resize/close.
});
});
Any ideas?
I think, you can do this with window.open().
1-only one window could be opened in the moment,
If you give same name, window.open(),
if there aren't any exist windows with same name, It will create a new one
else if there is a openned window with the same name, it will just refresh it.
2- I want to save window size and position in localStorage, and restore them on next open.
Yes, you can do this by attaching window.onresize event,
Here is a basic example,
chrome.browserAction.onClicked.addListener(function() {
var wOpt = getWindowDefaultOptions(); // options from localStorage
var win = window.open("http://www.example.com", "myscriptpopup", "width="+wOpt.width+", height="+wOpt.height+", top="+wOpt.top+", left="+wOpt.left);
win.onresize = function() {
var newOptions = {};
newOptions.width = this.innerWidth;
newOptions.height = this.innerHeight;
newOptions.top = this.screenY;
newOptions.left = this.screenX;
setWindowDefaultOptions(newOptions); //save Options to localStorage
}
});
//Default Options For Window
var winOptions = {
"width" : "200",
"height" : "100",
"top" : "50",
"left" : "50"
};
I am writing a Chrome extension that saves/restores your browsers window state - So, I save the state of a given window:
var properties = [ "top",
"left",
"width",
"height",
"incognito",
"focused",
"type"
];
var json = {};
var cache = chrome_window_object;
// copy only the keys we care about:
_.each(properties,function(key,value) {
json[key] = cache[key];
});
// then copy the URLs of the tabs, if they exist:
if(cache.tabs) {
json.url = [];
_.each(cache.tabs,function(tab) {
json.url.push(tab.url);
});
}
return json;
At some point in the future, I remove all windows:
closeAllWindows: function(done_callback) {
function got_all(windows) {
var index = 0;
// use a closure to only close one window at a time:
function close_next() {
if(windows.length <= index) return;
var window = windows[index++];
chrome.windows.remove(window,close_next);
}
// start closing windows:
close_next();
}
chrome.windows.getAll(got_all);
}
and then I restore the window using:
chrome.windows.create(json_from_before);
The window that is created has an extra tab in it, whatever was in the window that I just closed... I am completely floored, and I assume the problem is something that I am doing in the code that I haven't posted (it's a big extension). I've spent a few hours checking code line by line and making sure I'm not explicitly asking for this tab to be created. So - has anybody seen anything like this before?