I am trying to build out a harness for a page so that we can write tests against it. What I would like to be able to do is use a CSS selector to find the given element or elements instead of manually modifying the SearchProperties or FilterProperties.For a web test the CSS Selector seems far more intuitive then the SearchProperties do. Is there some mechanism for doing this that I am simply not seeing?
Try this...
https://github.com/rpearsondev/CodedUI.jQueryExtensions/
It adds extension methods to the BrowserWindow object...
var example1 = browser.JQuerySelect<HtmlHyperlink>('a.class1');
var example2 = browser.JQuerySelect<HtmlListItem>('li.class2');
However, I will let you know I'm having issues with it complaining about casting errors regularly.
Try browserWindow.executeJavascript if you return a control you found via css/xpath it returns the relevant uiControl object
const string javascript = "document.querySelector('{0}');";
var bw = BrowserWindow.Launch(new Uri("http://rawstack.azurewebsites.net"));
string selector = "[ng-model='filterOptions.filterText']";
var control = bw.ExecuteScript(string.Format(javascript,selector));
HtmlEdit filter= control as HtmlEdit;
filter.Text = "Alien";
As sjdirect noted, the jQuery extensions are probably the way to go if you want to use those type of selectors.
However, it seems that you may be interested in some abstraction that doesn't require directly setting search / filter properties on the UITestControl objects.
There are good abstractions that do not use the same selectors as jQuery, but provide a readable, consistent approach for finding elements in the page and interacting with them.
I would recommend also looking into Code First and CodedUI Fluent (I wrote the fluent extensions) or even CodedUI Enhanced (CUITe).
These provide query support for that looks like (from CUITe):
// Launch the web browser and navigate to the homepage
BrowserWindowUnderTest browserWindow = BrowserWindowUnderTest.Launch("https://website.com");
// Enter the first name
browserWindow.Find<HtmlEdit>(By.Id("FirstName")).Text = "John";
// Enter the last name
browserWindow.Find<HtmlPassword>(By.Id("LastName")).Text ="Doe";
// Click the Save button
browserWindow.Find<HtmlInputButton>(By.Id("Save")).Click();
Related
I am trying to insert value in textarea field using Excel automation, I have done a lot of research but don't get success.
I have used the scripts bellow.
IE.document.all("content").Item.Value = "Hi"
IE.document.all("content").Value = "Hi"
IE.document.all("content").innerHtml = "Hi"
None of the examples work.
Don't use Document.all
As per mozilla document.all is deprecated since HTML5 and may not work with your site.
This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible;. . .
Selectors you can use
Really, the selectors that are good to use would be .getElementById, .getElementsByClassName, .querySelector, and .querySelectorAll.
Solution using correct selector
I prefer to stick with querySelector and querySelectorAll.
Using your example, it appears you are attempting to grab the only textarea with a class of content, something like <textarea class="content"></textarea>.
Therefore, that example would look like
IE.document.querySelector(".content").innerHTML = "Hi"
Please try below code. Check if it's work or not.
IE.document.all("content").Text= "Hi"
Or
Try to to add text properties at the end of the code
I want to embed a HTML file inside of my electron app. I chose to use iframe, however - when I do this - it seems like I can no longer use node.js. Any attempt at using require("electron") will show that require is not defined. Any ideas?
Thanks in advance!
Stijn
if you don't mind a late answer, you should probably use a <webview>, as it gives you a more fine grained control on what you need.
If, however, you really need to use an <iframe>, you have two choices:
use parent.require (parent accesses the iframe parent, which should be your window)
on the load event, copy the parent window's require to the iframe one:
iframe.onload = function () {
const iframeWin = iframe.contentWindow
iframeWin.require = window.require
})
The only "downside" is that your included packages will be accessing the main window DOM instead of the iframe's one, which means that none of the iframe window global variables will exist and, more importantly, document will access the window DOM (querySelector and getElemementBy methods won't really work). Whether this is a problem for you depends on how you organise your code, so good luck there
I have a product package with several options in my Orchard site and I need users to be able to send an enquire based on a single option:
I've seen out there many articles about Tokens, Dynamic Forms (the examples using Dynamic Forms seem to be just for a single form type), I can think of many ways to achieve this but I don't know what is really the cleanest and fastest way to implement this functionality.
I would need a hint on what to keep researching to speed this up.
Thank you in advance
In your view, I'd wrap the button around an <a> tag something like this:
<a href="#(String.Format("/{0}/{1}", "x", y))" target="_blank">
//put button code or whatever here
</a>
Where 'x' is the extended url and y could be the query string such as: www.google.com/game/q=2
When you do this and get the redirect correct, in your driver for the page, you can get the page number from the url using something like this:
private readonly IHttpContextAccessor _httpContextAccessor;
var httpContext = _httpContextAccessor.Current();
var query = httpContext.Request.QueryString["q"];
I have been trying to scrape 10 websites for a website we are building with links to the original sites, on node.js using cheerio, problem we are getting is that some of the sites have changed which now uses ajax calls to bring their data, my question is how can we get that information, for instance trigger a button click first and then get the DOM.
secondly: same dom structure is not getting me all data, it is retrieving information for one page, but not getting the the elements on another page with identical DOM structure. any help would be appreciated.
Thanks and regards.
Edit 1: Relevant code
$('#ProductContent').filter(function(){
var price = undefined;
var ukulele = false;
var model = $(this).find('.ProductSubtitle').text().replace(/\n\s*/g,"");
if(model.indexOf(/m/i) != 0){
var description = $(this).find('.RomanceCopy').text().replace(/\n\s*|\r/g,"");
.
.code removed for brevity and the variables present here are populated
.
//this children is populated only for one page.
children = $(this).find('.SpecsColumn .SpecsTable table tbody').children('tr');
console.log('children: '+children.length)
console.log(guitar_url);
children.each(function(){
var key = $(this).children('td').first().text();
var value = $(this).children('td').last().text();
specs[key] = value;
console.log(specs);
});
Edit 2: Cherios Initialization
request(guitar_url,function(error,response,html){
if(!error){
var $ = cheerio.load(html);
$("#content #right-content").filter(function(){..children and other variables are populated inside here....})
}
})
To summarise all the comments you received:
Cheerio is minimalistic DOM reader inspired by jQuery. Its design is focused about reading data, and is not a browser emulator, where you could click a button.
Alternative is to use headless browsers like PhantomJS or CasperJS.
Those two are outside of Node.js scope, and you may have hard times transmitting the data back and forth from Node.js to headless browser.
If it is important for you to keep inside of Node.js environment, then you can use JSDOM.
All of them are more complicated to use than Cheerio, but if you want to manipulate the DOM, execute JavaScript on the DOM, etc... Then this is your best bet.
Removing the 'tbody' tags solved the problem, once they were removed it started to fetch the data normally for all three sites.
I have a page I'd like to embed a news-feed widget into (so that the feed from some remote site will be displayed in my site).
While there are quite a few free news-feed widgets available out there (a partial list is here: http://allwebco-templates.com/support/S_script_newsfeed.htm), They all require insertion of complex code into the html page, while all the parameters are hard-coded into the generated code, which looks something like this:
insertedWidgetText = "<script id=\"scrnewsblock10795953\" type=\"text/javascript\">...script specific parameters go here...</script>"
let feedWidget = toWidgetBody [hamlet|#{preEscapedText insertedWidgetText}|]
This doesn't integrate well with Yesod's approach as it requires specifying to Hamlet that the content is preEscapedText, which in turn disables the ability to use Hamlet's processing to alter parameters of the widget dynamically (So in case I want the widget to use a different source, for example, I need to statically change the quoted text and cannot use Hamlet's variable substitution).
Of course I could do some text manipulation myself, tailor built for the widget I'm using, but that doesn't seem like the "right" solution (especially if I want to have the embedded text in some external file and not in the middle of my code as in the example above).
Can the above mentioned issue have a better solution than the one I thought about?
Is there an implementation of a news-feed widget in Haskell/Yesod that I can use as a plugin?
Note: I'm a very poor javascript programmer, but solutions in that direction are also welcomed.
Thanks,