I'm trying to get the text from this html but its not working. Can you help me solve this? thanks
html:
<h1 class="sc-ebzWDT igyUpb" data-test-id="issue.views.issue-base.foundation.summary.heading">
Login Test
code:
element = await page.waitForSelector("[sc-ebzWDT igyUpb]");
title = await page.evaluate(element => element.textContent, element);
error:
(node:4948) UnhandledPromiseRejectionWarning: Error: Evaluation failed: DOMException: Failed to execute 'querySelector' on 'Document': '[sc-ebzWDT igyUpb]' is not a valid selector.
That's an incorrect selector for a class name, try:
element = await page.waitForSelector(".sc-ebzWDT.igyUpb]");
title = await page.evaluate(element => element.textContent, element);
You can read more about CSS Selectors here.
Related
I am working on SQfLite database. I am trying to save data but getting an error during saving data. I am using Chrome to check my output. The error is No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider). Here is a code which i think having a problem.
Directory documentsDirectory = await getApplicationDocumentsDirectory();
String path = join(documentsDirectory.path, "student.db");
return await openDatabase(path, version: 1, onCreate: _onCreate);
Here is a code for inserting data:
Database? db = await instance.database;
var id = await db!.insert('student', data);
I am using Chrome for checking output, may be this is a reason for error or whatever reason please guide me.
Plugins added
sqflite: ^2.0.2+1
get: ^4.6.5
path_provider: ^2.0.11
the error is:
Error: MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider)
at Object.throw_ [as throw] (http://localhost:65116/dart_sdk.js:5067:11)
at MethodChannel._invokeMethod (http://localhost:65116/packages/flutter/src/services/restoration.dart.lib.js:1560:21)
at _invokeMethod.next ()
at http://localhost:65116/dart_sdk.js:40571:33
at _RootZone.runUnary (http://localhost:65116/dart_sdk.js:40441:59)
at _FutureListener.thenAwait.handleValue (http://localhost:65116/dart_sdk.js:35363:29)
at handleValueCallback (http://localhost:65116/dart_sdk.js:35931:49)
at _Future._propagateToListeners (http://localhost:65116/dart_sdk.js:35969:17)
at [_completeWithValue] (http://localhost:65116/dart_sdk.js:35817:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:65116/dart_sdk.js:35838:35)
at Object._microtaskLoop (http://localhost:65116/dart_sdk.js:40708:13)
at _startMicrotaskLoop (http://localhost:65116/dart_sdk.js:40714:13)
at http://localhost:65116/dart_sdk.js:36191:9
I am trying to get HTML from an URL using Puppeteer without following redirection nor triggering related HTTP requests (CSS, images, etc.).
According to Puppeteer documentation, we can use page.setRequestInterception() to ignore some requests.
I also found several SO questions such as this one that advises to use request.isNavigationRequest() and request.redirectChain() to determine if request is "main" or a redirection.
So I tried it, but I get Error: net::ERR_FAILED errors.
Example with http://google.com (which, when requested, answers with a 301 with Location: http://www.google.com/ header).
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', (interceptedRequest) => {
if (
interceptedRequest.isNavigationRequest()
&& interceptedRequest.redirectChain().length !== 0
) {
interceptedRequest.abort();
} else {
interceptedRequest.continue();
}
});
await page.goto('http://google.com');
const html = await page.content();
console.log(html);
await browser.close();
})();
Ran using node --trace-warnings file.js, I get:
(node:14252) UnhandledPromiseRejectionWarning: Error: net::ERR_FAILED at http://google.com
at navigate (/path_to_working_dir/node_modules/puppeteer/lib/cjs/puppeteer/common/FrameManager.js:115:23)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async FrameManager.navigateFrame (/path_to_working_dir/node_modules/puppeteer/lib/cjs/puppeteer/common/FrameManager.js:90:21)
at async Frame.goto (/path_to_working_dir/node_modules/puppeteer/lib/cjs/puppeteer/common/FrameManager.js:416:16)
at async Page.goto (/path_to_working_dir/node_modules/puppeteer/lib/cjs/puppeteer/common/Page.js:789:16)
at async /path_to_working_dir/file.js:17:3
at emitUnhandledRejectionWarning (internal/process/promises.js:168:15)
at processPromiseRejections (internal/process/promises.js:247:11)
at processTicksAndRejections (internal/process/task_queues.js:94:32)
(node:14252) Error: net::ERR_FAILED at http://google.com
at navigate (/path_to_working_dir/node_modules/puppeteer/lib/cjs/puppeteer/common/FrameManager.js:115:23)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async FrameManager.navigateFrame (/path_to_working_dir/node_modules/puppeteer/lib/cjs/puppeteer/common/FrameManager.js:90:21)
at async Frame.goto (/path_to_working_dir/node_modules/puppeteer/lib/cjs/puppeteer/common/FrameManager.js:416:16)
at async Page.goto (/path_to_working_dir/node_modules/puppeteer/lib/cjs/puppeteer/common/Page.js:789:16)
at async /path_to_working_dir/file.js:17:3
(node:14252) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
at emitDeprecationWarning (internal/process/promises.js:180:11)
at processPromiseRejections (internal/process/promises.js:249:13)
at processTicksAndRejections (internal/process/task_queues.js:94:32)
Using the http://www.example.com URL ( instead of http://google.com) works fine: no error and I get what a curl http://www.example.com would.
How can I discard unwanted redirection requests but still be able to perform actions on the "main" page (page.screenshot(), page.content(), ...)?
I know this one is a bit old but having encountered the same issue I thought it might still worth sharing how to resolve this issue.
The reason you're getting the net::ERR_FAILED error is because after the redirection happens, i.e. interceptedRequest.redirectChain().length != 0, interceptedRequest which represents the redirected request (i.e. to https://www.google.com/ in your case) now becomes the main navigation request as is evident by interceptedRequest.isNavigationRequest() being true, but you then go on to call abort() on it. According to this test spec in the Puppeteer source, aborting the main navigation request during a Page.goto() will result in a net::ERR_FAILED error. The solution is to catch and appropriately handle this error when it is thrown by the Page.goto() since it is not unexpected:
try {
await page.goto('http://google.com');
} catch(e) {
if (e instanceof Error && e.message.startsWith('net::ERR_FAILED')) {
console.log('Redirection aborted');
} else {
throw e;
}
}
I have a property errorMessage declared in my ts component. I need to store a string within this that contains multiple lines that need to be separated by a line. '\n' doesn't seem to work with this. Please suggest the way to do this.
In ts component:
this.errorMessage = 'An error has been encountered. \nDetails:\n' + errorString;
In html template:
<p>{{errorMessage}}</p>
You can do the one trick here as you can use [innerHTML] attribute to show you html that is inside your errorMessage
You have to modify your code in component like
this.errorMessage = 'An error has been encountered. <br>Details:' + errorString;
And in your template you can render you above message by using above attribute like
<p [innerHTML]="errorMessage"></p>
The above code will render your errorMessage as a HTML not a string so line break will also rendered
Your best solution would be to just use innerHTML instead.
Change this:
this.errorMessage = 'An error has been encountered. \nDetails:\n' + errorString;
<p>{{errorMessage}}</p>
To this:
this.errorMessage = 'An error has been encountered. <br>Details:<br>' + errorString;
<p [innerHTML]="errorMessage"></p>
However there are some caveats to this solution. You can find more about it here
https://angular.io/guide/security
Problem: I'm running into an issue where I am unable to tokenize the credit card information posted inside of the card stripe element I am mounting to my component.
I am currently using the Nebular stepper component (https://akveo.github.io/nebular/docs/components/stepper/overview#nbsteppercomponent) and have a nested child component with the following ts code:
public async fetchCardInput(): Promise<any> {
let address: Address = this.ccAddress.fetchAddressData();
let name = this.getCardholderName();
let line2 = address.getAddressLine2();
let cardTokenPayload = {
name: name,
address_line1: address.getAddressLine1(),
address_city: address.getCity(),
address_state: address.getState(),
address_zip: address.getZipCode(),
country: this.constants.US,
currency: this.constants.USD
};
if (line2) {
cardTokenPayload['address_line2'] = line2;
}
const { token, error } = await this.stripe.createToken(this.card, cardTokenPayload);
if (error) {
console.log('Something went wrong: ', error);
return null;
} else {
console.log('SUCCESS! Token: ', token);
let data = {
tokenId: token.id,
address: address,
cardholderName: name
}
return data;
}
}
html (pulled out the html and ts from the child component but it's still behaving the same way):
<nb-step label="Payment / Payout">
<div class="heading">{{ constants.PAYMENT_INFORMATION }}</div>
<label class="input-label">{{ constants.CREDIT_CARD_INFORMATION }}</label>
<div class="card-container">
<div id="card-element" #cardElement></div>
</div>
<div *ngIf="error" class="error mt-10">{{ error }}</div>
</nb-step>
The thing is, this implementation works completely fine when it's not nested inside of the Nebular component. Has anyone found a work-around for this issue or at least familiar with Nebular components and what they're doing under the hood?
EDIT: Adding the browser exception:
ERROR Error: Uncaught (in promise): IntegrationError: We could not retrieve data from the specified Element.
Please make sure the Element you are attempting to use is still mounted.
I am using Angular 8 and Nebular 4.5.0.
Thanks in advance!
I am trying to user puppeteer waitForXPath with an XPATH but I am getting following error
"Error: Evaluation failed: DOMException:
Failed to execute 'querySelector' on 'Document': '//footer//span[#data-icon="send"]'
is not a valid selector.
I have tested this XPATH in Chrome's inspect element. I don't know why puppeteer is giving me error for selector when I am using XPATH to find the element.
Line which is giving me error: await page.waitForXPath('//footer//span[#data-icon="send"]')
This is my puppeteer and other package versions:
"puppeteer": "^2.1.1",
"vue": "^2.5.16",
"vue-electron": "^1.0.6",
document.querySelector accepts css:
await page.waitFor('footer span[data-icon="send"]')
I use chained promises as below:-
.then(page => page.waitFor(10000))
.then(() => _page)
.then(page => page.waitForXPath("//a[starts-with(./#class,'nav-link daterange') and contains(.,'Last 30 days')]"))
It works reliably and is very readable if you know XPath