I'm transforming a website using tritium, and there's a chunk of inline javascript that interferes with how the mobile site should work. There's really only one line that I want to take out, however, so I can't really just remove the whole chunk. Right now what I'm doing is just fetching the text and using a regex replace to remove the line:
$(".//script[contains(text(), "part of inline js")] {
# an example of the line i want to take out
text() {
replace("document.getElementById('someid').value = 'somevalue';") {
set("")
}
}
}
This seems kind of clunky, though, especially if the section I want to change gets very long. Is there a better way of doing this?
So I would probably use a regular expression in this case. Once you've got a unique enough capture, you can just capture the rest of the line.
In this case maybe it's something like:
replace(/.*getElementById\('someid'\)\.value.*/, "")
As of right now this is the only way to edit inline scripts.
Related
I'm trying to set up a string match using handlebars in SendGrid. As I understand it, you can only use the if statement with booleans so I'm trying via {{equals}} instead. This works fine but I'm then trying to inject that 'thing' into the result. The result I'm after in the below is that if the data = TEXT then the email reads "This is some TEXT"
{{#equals thing "TEXT"}}
This is some {{insert thing}}
{{/equals}}
Using {{insert thing}} outside the {{equals}} handlebar is fine but when inside it doesn't return anything. I just get "This is some"
Does anyone know if this is supported or if there is a better way?
Thanks.
I'm not entirely sure how to explain it, but it seems that within blocks in handlebars there is a new scope. This works well for loops, where the scope is the current item in the loop, but less well for conditionals where the scope doesn't seem to include anything. You can get back to the root scope using the #root keyword though, so you can use that to get something from outside of the block. In this case, you can use it like this:
{{#equals thing "TEXT"}}
This is some {{insert #root.thing}}
{{/equals}}
I have a page which has a script tag. The script inside that tag is very long, but I would like to debug it. Unfortunately, I cannot scroll to the relevant place in the Console, because after a certain length the script is simply not displayed, see the attachment:
As you can see, it ends with
return !filt...
The actual function looks like this:
this.validate = function(filters) {
for (var filter in filters) {
if (!innerValidation(filters[filter].filterType, filters[filter].evaluatedValue, data[filters[filter].key])) {
return filters[filter].isOr;
}
}
return !filters[filter].isOr;
};
Question: Why does Chrome truncate my script and how could that be changed?
Note, that I know I could load it from an external file, but I am actually interested to know the cause of this behavior.
The display of the script is truncated but it still parses and runs the code correctly. You should be able to view the full code in the Sources tab under the relevant host and put breakpoints in there.
If you have a long script, it is best to make that into its own file instead. This will provide you with the best debugging experience.
The Elements panel truncates large scripts to help keep things fast and there is no way to undo this. Therefore, you would need to use some external debugging tools to try and get at this, but even then most of them work best with external script files as well.
Inline scripts should be very short if ever used. For any decent sized chunks of scripting, allocate that into its own file.
I am using Brett's Mr. PHP thumb caching script along with phpThumb to create my thumbs. It works extremely well, except for one thing... I cannot get it to set and process the UnSharpMask filter. The relevant part of the script looks like this:
// generate the thumbnail
require('../phpthumb/phpthumb.class.php');
$phpThumb = new phpThumb();
$phpThumb->setSourceFilename($image);
$phpThumb->setParameter('w',$width);
$phpThumb->setParameter('h',$height);
$phpThumb->setParameter('q','95'); // set the quality to 95%
$phpThumb->setParameter('fltr[]','usm|80|0.5|3'); // <--- THIS SHOULD SET THE USM FILTER
$phpThumb->setParameter('f',substr($thumb,-3,3)); // set the output file format
if (!$phpThumb->GenerateThumbnail()) {
error('cannot generate thumbnail');
}
I'm guessing there's a problem with my syntax, since the fltr[] parameter requires brackets. I have tried escaping the brackets like so: 'fltr[]' but that didn't work either.
I've used several other possible parameters with good success (zoom cropping, max height, max width, etc...) Everything seems to work except the filters (including usm - UnSharpMask).
I don't get any errors. It spits out thumbs all day long. They're just not sharpened.
For reference, here's the official phpThumb readme file that discusses all the possible settings and filters.
Thanks for looking.
Well after much trial, error, and aggravation, I finally discovered the solution buried in one of the demo files that come with phpThumb.
It's a matter of removing the brackets all together. Basically changing this line:
$phpThumb->setParameter('fltr[]','usm|80|0.5|3');
to this:
$phpThumb->setParameter('fltr','usm|80|0.5|3');
After that, it's only a matter of tweaking the settings to get the desired amount of sharpness.
I'm using Microsoft UI automation + White framework. Is it possible to get a full path from to the control from the top parent, and then use it to find an element? For example, use UI spy to get the full path, and then somehow get the control by the taken path?
Thanks
I use the unmanaged version of MSUIA and don't use white, but something like this should do what you are asking. Pass in an element.
CUIAutomation auto = new CUIAutomation();
var desktop = auto.GetRootElement();
var walker = GetRawTreeWalker();
while (true)
{
element = walker.GetParentElement(element);
if (auto.CompareElements(desktop, element) == 1)
{
break;
}
winPath = AppendWinPathPart(winPath, element);
}
AppendWinPathPart is a call to a method that builds something like a path in string form that I use in my automation. It is much like XPath for MSUIA.
I have done something in the past similar to what it sounds like you're trying to do. Unfortunately, it's not necessarily all that easy to do.
I essentially built my own simplified version of UI Spy that used some code similar to what's in the answer from #chrismead above to build a '\' delimited path of automation IDs (unfortunately, as you may have already discovered, AutomationIDs can be unreliable, so for the sake of robustness I also had to add the capability to identify AutomationElements by things like name, position among siblings, or position relative to parent).
Then, I had code in another application that could take those paths as input in order to locate those specific AutomationElements and interact with them.
I am trying to run the Selenium driver with Perl bindings, and due to the lack of examples and documentation, I am running into some roadblocks. I have figured out how to do some basic things, but I seem to be running into some issues with other simple things like validating the text on a page using Remote::Driver package.
If I try to do something like this:
$sel->get("https://www.yahoo.com/" );
$ret = $sel->find_element("//div[contains( text(),'Thursday, April 26, 2012')]");
I get a message back that the element couldn't be found. I am using xpath because the driver package doesn't appear to have a sub specific for finding text.. at least not that I've found.
If my xpath setup is wrong or if someone knows a better way, that would be extremely helpful. I'm having problems with some button clicking too.. but this seems like it should be easier and is bugging me.
Finding text on a web page and comparing that text to some "known good value" using Selenium::Remote::Driver can be implemented as follows:
File: SomeWebApp.pm
package SomeWebApp;
sub get_text_present {
my $self = shift;
my $target = shift;
my $locator = shift;
my $text = $self->{driver}->find_element($target, $locator)->get_text();
return $text;
}
Somewhere in your test script: test.pl
my $text = $some_web_app->get_text_present("MainContent_RequiredFieldValidator6", "id");
The above finds the element identified by $target using the locating scheme identified by $locator and stores it in the variable $text. You can then use that to compare / validate as required / needed.
https is a tad slower loading than http. Although WebDriver is pretty good about waiting until it's figured out that the requested page is fully loaded, maybe you need to give it a little help here. Add a sleep(2); after the get() call and see if it works. If it does, try cutting down to 1 second. You can also do a get_title call to see if you've loaded the page you think you have.
The other possibility is that your text target isn't quite exactly the same as what's on the page. You could try looking first for one word, such as "April", and see if you get a hit, and then expand until you find the mismatch (e.g., does this string actually have a newline or break within it? How about an HTML entity such as a non-breaking space?). Also, you are looking for that bit of text anywhere under a div (all child text supposedly is concatenated, and then the search done). That would more likely cast too wide a net than not get anything at all, but it's worth knowing.