Protractor - Enter Key not working - return

I am trying to run some protractor tests in Safari (they run fine in Chrome).
The problem seems to be that the return key is not working correctly in sendKeys() method.
The value is being not send ( - is undefined)
Here is what I did on the input object:
input.sendKeys(value + '\n');
Also, I tried
input.sendKeys(value + protractor.Key.ENTER);
But getting the same results.

According to the webdriverjs doc, the correct syntax seems to be:
input.sendKeys(value, protractor.Key.ENTER);
Have you also tried to send the text and the enter key separately:
input.sendKeys(value);
input.sendKeys(protractor.Key.ENTER);

You should be able to do something like this:
browser.actions().sendKeys(protractor.Key.ENTER).perform();
If you want to use a combination of keys in protractor, try this (for example SHIFT + TAB):
browser.actions().sendKeys(protractor.Key.SHIFT, protractor.Key.TAB).perform();

Related

This document requires 'TrustedScriptURL' assignment in Google Sheets

I have a Google Spreadsheet where I have the following information on specific cells in the sheet:
Cell B1: Has the URL http://www.google.com.co/search?q=NASA+watching+now%3A+site%3Awww.youtube.com
Cell B2: has the following formula: =IMPORTXML(B1,"//title")
Here is the link of the Google spreadsheet - if you want to test from your side.
And here is the Google Spreadsheet I'm working on - which, I want to get the specific data:
Title: Text (in the h3 HTML tag of the result item).
Url: Link (in the <a> HTML tag of the result item)
Description: Text next to the thumbnail of the result item.
See screenshot with the data to get using IMPORTXML:
The previous code returns the title of the given URL - in this case, the URL stored in the B1 cell.
It was working without problems (since 12/02/2022 - dd/MM/yyyy) until today (13/02/2022 - dd/mm/yyyy).
I checked the Chrome console "F12 Developer tools" and I get this error:
This document requires 'TrustedScript' assignment.
injectIntoContentWindow # VM364:27
By clicking the # VM364:27 line, the following code is shown:
function injectIntoContentWindow(contentWindow)
{
if (contentWindow && !injectedFramesHas(contentWindow))
{
injectedFramesAdd(contentWindow);
try
{
contentWindow[eventName] = checkRequest;
contentWindow.eval( /* ERROR with and (X) is shown here. */
"(" + injectedToString() + ")('" + eventName + "', true);"
);
delete contentWindow[eventName];
}
catch (e) {}
}
}
Searching on the internet, I barely could get the causes of this error:
Google Chrome update - making security stricter.
Chrome extensions - try to disable such extensions and try again.
CPS (Content-Security-Policy) - must be honest = I don't understand this point; it's from the website to scrape the data OR from Google Sheets the CPS is the root cause?
The solutions given to this problem are in Python - with the use of DOMPurify - as is described in this answer, but, I don't know and neither have found any clues about this problem and its solution in Google Spreadsheets.
I've tried:
Recover previous working Google Spreadsheet version - the result is that the formula re-evaluates and no result is returned; looking in Console, the This document requires 'TrustedScriptURL' assignment message shows.
Disable Google Chrome installed extensions - I only have AdBlock (this code was working without issues), anyway, I turned off, reload the spreadsheet and the error mentioned above raises in Console.
Using another page - I tried with Wikipedia and Wiki.fandom and it works - i.e. data is returned. Probably in this case, Google injected in their searcher an script for avoid injection? - I'm really not sure, only speculating/rambling here.
Another possible cause I consider is maybe my IP was blacklisted or blocked, but, I'm not sure.
My browser information:
Chrome version: 98.0.4758.82 (Build oficial) (64 bits) (cohort: Stable)
Windows 10 Version 21H2 (Build 19044.1466)
Is there any way to solve this error in Google Sheets?
PS: I'm interested in know the workaround using google sheets and/or custom scripts - via script editor/Apps Script. The use of IMPORTXML function is not mandatory - I find curious that it was working and then today, not anymore.
I will just leave this here:
=INDEX(UNIQUE(REGEXREPLACE(QUERY(IMPORTXML(A1, "//a/#href"),
"where Col1 contains 'youtube.com/'"), "\/url\?q=|&sa=.*", )))
=IMPORTXML(A1, "//title")
=IMPORTXML(A1, "//h3")
TL;DR: This document requires 'TrustedScript' assignment error is not the root cause of the delay of the IMPORTXML function - probably there is other cause(s) (outside of the developer's handling), but, after all, the code works - see working google spreadsheet - just, wait until the results are shown or use another way to web-scrapping the desired data.
Since the This document requires 'TrustedScript' assignment message stays appearing in the Console of the browser, but, the code I posted on my question (and the code posted by SO user player0 in their answer) works, it seems to me that the delay of the response using IMPORTXML might be due its buggy functionality and/or some restriction Google detected by doing multiple requests.
So, here are my tips about this:
Check very closely how the page where the data will be extracted from and its structured before doing excessive requests - or you might face a significant delay in the response of the IMPORTXML function - as I experienced it.
Get more familiar with XPath and check if the data is dynamically generated in the page - this makes even harder to get the desired data using this way of scrapping.
This is the spreadsheet with the desired results - if anyone is interesed1.
1 Check the "Results-mix" sheet (which contains both the code I manage to create and the code provided by player0 in their answer).
If you really want to get similar results in a less convoluted way, consider use another strategy for web-scrapping or use official APIs - when available.

Issue in pexpect when text wraps within session

I am working on a pexpect script that is running populating an output file name and then a prompt for the file's parameters.
The program that the script runs asks for Device: then Parameters: always on the same line.... so if the file path-name that is entered for Device is long, sometimes the Parameters prompt wraps to the next line.
My code looks like..
child.expect_exact('Device:')
child.sendline('/umcfiles/ftp_dir/ftp_peoplesoft/discount/AES_DISCOUNT_15010.TXT')
child.expect_exact('Parameters:')
This times out.. and here is what is in child.before
' /umcfiles/ftp_dir/ftp_peoplesoft/discount/AES_DISCOUNT_15010.TXT Param\r\neters: "RWSN" => '
so the expect fails... (a child.expect('Parameters:') also fails)
How can I ignore the \r\n if it is there, because depending on the length of the path/filename I am using it may not be there at all, or be in a different position.
Thanks!
Actually... I found a way to calculate how much is left on the given line, and dynamically set my expect to how much of the Parameter prompt should be visible... seems to be working
#look for end of line and fix how much of 'Parameters:' we look for in pexpect
dlen = 80-len('Device: /umcfiles/ftp_dir/ftp_peoplesoft/discount/AES_DISCOUNT_15010.TXT')
pstr='Parameters:'
if dlen > len(pstr):
dlen=len(pstr)
else:
dlen=dlen-3 #remove the /r/n
child.expect(pstr[0:dlen])

Drupal Curl, $GET

I am creating a Drupal 7 node from remote. In my server I have a script that uses
now=$(date)
curl --data "date=$now" http://website.com
That is supposed to send the value of $now to the url. In my remote nodecreate.php form I am using
$node->field_date[$node->language][0]['value'] = $_GET['date'];
To set the value of the date field in the node. Problem is that the node is created successfully, but the date is blank.
I have tried other variations such as setting a value to a string in the remote nodecreate.php like this
$date = $_GET['date'];
$node->field_date[$node->language][0]['value'] = $date;
however that did not work either. Anyone got ideas what is wrong here?
You probably should use the following :
$node->field_date[LANGUAGE_NONE][0]['value'] = $date;
I suppose here that you are using translation on node but not translatable fields.

sendkeys command causing exception in selenium webdriver on IOS safari

I have been trying to run some sample Remote WebDriver tests on the Safari browser on the IOS Simulator 7.0 (IPhone) but my tests give an exception every time I try to type in values on a text box. Just trying to use the example from iosdriver
DesiredCapabilities safari = IOSCapabilities.iphone("Safari");
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://<someip>:4444/wd/hub"), safari);
driver.get("http://hp.mobileweb.ebay.co.uk/home");
WebElement search = driver.findElement(By.id("srchDv"));
search.sendKeys("ipod");
search.submit();
gives me the exception
a "org.openqa.selenium.NoSuchElementException: cannot find element for criteria :{"AND":[{"l10n":"none","expected":"UIAElement","matching":"exact","method":"type"},{"l10n":"none","expected":"Address","matching":"exact","method":"name"}" .
Anyone else run into this? It is identifying the element but typing in values fail..It works fine when I try it on firefox on my desktop.
I am no expert, but am familiar with selenium webdriver..
Are you sure that the id for "search " --- ('srchDv') actually exists on the page you are trying to automate?
if so
i would then look into the UIA -Element Hierarchy / Accessibility link to UIA Element Class reference
Hope this is helpful
You have an incorrect selector. The page you are automating does not have an id srchDv. If you are getting the search box, then you need to use:
driver.findElement(By.id("gh-ac")).clear();
driver.findElement(By.id("gh-ac")).sendKeys("ipod");
Also, instead of using submit, personally i would follow the way that your user would commit the action, and that's by clicking the search button.
driver.findElement(By.id("gh-btn")).click();

Any way to see map results in a mapreduce function?

For debugging purposes it would be great to be able to see just what you are getting back from the map method. Is this possible in ruby?
To do this in the Mongo shell, you can define you own debug version of the emit() function to print trace information.
function emit(k, v) {
print("emit");
print(" k:" + k + " v:" + tojson(v));
}
Check out Troubleshooting MapReduce in the MongoDB docs for more info.
I know the Mongo documentation recommends defining your own emit function, but I find it easier to instead use print() directly in my map- and reduce-functions while I watch Mongo's log.
Just put any print()'s in your code, run tail -f /var/log/mongodb/mongodb.log, then run your code. You should see the print()'s output to the console.
Here's a few of the benefits:
Ability to debug the reduce() function – defining your own emit() doesn't help here
No need to define the emit() function every time you fire up the mongo console
Write your code in your editor instead of going back and forth between console and IDE
Ability to do code generation and variable interpolation in your native language

Resources