I'm writing JavaScript to automate Chrome operations using puppeteer in Node.js.
For example, when the URL "https://www.example.com/" is displayed and the button with id btn-next is pressed
When the element with id success is displayed on the transition destination page, click the link with id btn-submit
The following source works fine.
const puppeteer = require ('puppeteer');
puppeteer.launch ({
headless: false,
}). then (async browser =>{
const page = await browser.newPage ();
await page.setViewport ({width: 1200, height: 800});
await page.goto ('https://www.example.com/');
await page.click ('# btn-next');
await page.waitForSelector ('# success');
await page.click ('# btn-submit');
browser.close ();
});
For example, id is "success", but it is displayed in the normal pattern, but it is not displayed at the time of congestion
If an error page is displayed, if an error page is displayed, return to the top page
I want to do something like pressing the button with id btn-next again.
The image looks something like this, but of course it doesn't work.
while (true) {
var item = page. $('# success');
if (item! = undefined)
{
break;
}
else
{
await page.goto ("https://www.example.com/");
await page.click ('# btn-next');
}
}
I don't understand async/await, but I'd appreciate it if you could give me a hint.
-
Answer # 1
Related articles
- i can't get the value of the input element of html in javascript
- javascript - jquery i want to select a specific element
- javascript - i want to specify a variable for the width of the element
- javascript - i want to rewrite the inside of an element using the append method in jquery
- javascript - is there a way to check if the string is escaped with the chrome developer tool?
- javascript - how to write the process to put the id of the clicked element in a variable
- i want to check the elements of a multidimensional array with javascript
- javascript - i want to get an element of iframe with react
- javascript - react how to write an input check
- javascript - i want to change the process using check in jquery
- javascript - i want to apply a method only to a specific element for the element acquired by queryselecterall
- javascript - i want to get an element from a multidimensional array
- i want to put the data sent from javascript in the html input element
- javascript - recipe draft of the format check function of the character string defined date
- i want to run javascript eventlistener on the html button element obtained from api (php)
- javascript - [vuejs] in v-for, i added a specific element () at a specific number of times, but it is surrounded by tags and it
- javascript - show/hide div element with jquery
- javascript - how to get any element with documentqueryselector
- javascript - regular expression to check if it is a url
- javascript - inserting an element using insertadjacenthtml inside a loop shows undefined above the first child element
- javascript : Finding the same characters in a string
- javascript : Why am I getting sass is not a function error in gulp when using the gulp-sass module?
- javascript : How to query data with PostgreSQL in reverse order
- javascript : I want to UPDATE using placeholders in Node + MySQL
- javascript : A value different from the displayed value is UPDATEd to MySQL.
- javascript : How to partition an array from the server side
- javascript : How to run selenium webdriver on vps?
- javascript : Very long C code execution #
- javascript : Create a video conference
- javascript : How to track the addition of a new block to the page in puppeteer?
await page.click ('# btn-next')
immediately afterpage. $('# success')
I don't think it's going to work because it's before the page transition is complete, and I think you need to wait for the page transition usingpage.waitForNavigation ()
.And the return value of
page. $('# success')
is of typePromise
, so when writing synchronously,await
Is required.I implement it as follows.