Tips for extracting dynamically loaded content from a website using Node.js and Selenium?

I'm currently encountering some challenges when trying to scrape a website that utilizes react for certain parts of its content, and I'm unsure about the reason behind my inability to extract the data.

Below is the HTML structure of the website: view image

My goal is to retrieve the text of the button with

data-test="shipItButton"

However, upon running my code, I encounter the following error:

(node:23294) UnhandledPromiseRejectionWarning: NoSuchElementError: no such element: Unable to locate element: {"method":"css selector","selector":"[data-test=shipItButton]"}

Here is the code snippet I am currently using:

const webdriver = require("selenium-webdriver");
const By = webdriver.By;
const until = webdriver.until;

const driver = new webdriver.Builder()
  .forBrowser("chrome")
  .build();

let getData = async(url) => {
  await driver.get(url);
  let element = await driver.findElement(By.css('[data-test=shipItButton]'));
  await driver.wait(until.elementIsVisible(element), 15000)
    .then(element => getText())
    .then(text => console.log("Extracted text: ", text))
    .catch(err => console.log("Failed to retrieve: ", err));
}
getData("https://www.target.com/p/animal-crossing-new-horizons-8211-nintendo-switch/-/A-76780148")

Any suggestions on resolving this issue?

Answer №1

Rectify this section.

Selector("button[data-test='shipItButton']")

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The specified <model> has not been declared

Within my codebase, I have defined multiple schemas. One of them is functioning perfectly: var mongoose = require('mongoose'), Schema = mongoose.Schema; var NewsSchema = new Schema({ name: String, route: String, remoteU ...

Present pop-up messages in the most sophisticated manner

I have successfully created an AngularJS app that is functioning well. Now, I am faced with the challenge of displaying different pop-ups based on specific conditions being met. I am unsure of the best approach to take. Currently, I am considering two op ...

Stop the replication of HTML/CSS styles during the extraction of content from a div

Is there a way to prevent the copying of CSS properties, such as font styles and sizes, when content is copied from a div? I want only the plain text to be copied to the clipboard, without any formatting applied. ...

Error: The function register.route(...) does not support the use method

Upon using express.Router(), I encounter an error when attempting to apply the use method, resulting in the following message: TypeError: register.route(...).use is not a function Code /server/routes const express = require('express'); const re ...

Senecajs responded with a result that was neither an object nor an array, displaying a Promise

Seeking guidance on incorporating promises into my Seneca modules. Firstly, there is the server.js file that exposes a route: var express = require('express'); var app = express(); var Promise = require('bluebird'); var seneca = requ ...

Running PHP scripts from JavaScript

Currently working on a PHP project that involves a dropdown select button in a webpage. The goal is to call a JavaScript function whenever the value of the dropdown changes, and then pass this selected value to retrieve additional details from a MySQL da ...

npm causing problems with babel-cli

While working on building a section of my library with Babel, I've encountered some issues when running Babel commands through npm. In my npm script named "build," the following commands are executed: { "prebuild": "rm -rf && mkdir dist", ...

The issue with the .map function in Node.js causing the Express server to prematurely return the response object

I am currently working on creating a customized POST function for an express application in Node.js, inspired by Django's built-in REST methods. This function involves checking the mongo database for valid foreign keys and duplicates. The code snippet ...

Using a for loop in JavaScript to dynamically display TextBoxFor(model=> model[i].prop) in an MVC application

I need some help getting this code to function correctly: $('#ddl').change(function () { $('#cont').html(''); var count = getCount($('#ddl').val()) for (var i = 0; i < count ; ...

Storing persistent JSON data in a mobile app built with HTML5 involves utilizing the local storage capabilities of the

I am currently working on a mobile app using PhoneGap that is based on HTML technology. When the app is opened for the first time, my goal is to have it download a zip file that includes a JSON file and media files such as images or audio. Once the zip f ...

Execute protractor, selenium, and Python unit test in sequence

I have a set of Protractor Selenium tests and another set using Python unit test. Both sets are independent of each other. I want to run a Protractor test first, and if it passes, then run a Python test. If the Python test also passes, I want to run the Pr ...

Navigating the Promise Flow in NodeJS: Tips for Regulating Execution

I am trying to gain a better understanding of nodeJS by using the following code to execute CMD operations one by one. However, I have noticed that due to the event loop, it gets executed in random variations. Here is my code: const exec = require('c ...

Unveiling the secrets to integrating real-time graphical representations of sensor

I have successfully connected a temperature sensor to the BeagleBone Black [BBB] board. Every 1 second, the sensor senses the temperature and passes it to the BBB. The BeagleBone then dumps this data into a MySQL database on another computer. Now, I want t ...

When working with AngularJS, you can enhance your application by implementing a global AJAX error handler if one has

Is there a way to set a global AJAX handler that will only be called if an error handler is not already defined for a specific AJAX call? Some of my AJAX calls need to execute certain logic if an error occurs (such as re-enabling a button), while others s ...

Organize elements with jQuery, remove, detach, clone, and append without worrying about memory leaks

I am facing a challenge with a parent div that contains approximately 300 child divs, each one containing an image and some text. I have an array with the necessary information to reorder these divs using references. However, whenever I loop through the a ...

Which tool would be better for starting a new Angular project: angular-seed or yeoman?

I'm having trouble deciding on the best approach to create a new AngularJS application. There seem to be various methods available, such as using angular-seed from https://github.com/angular/angular-seed or yeoman - http://www.sitepoint.com/kickstar ...

Unable to prevent git from continuously keeping track of package-lock.json

After updating to npm v5, a new package-lock.json file is generated when running npm install. Although it is advised to commit this file, I am facing an issue where the content of this file differs between my development machine and the server. Even if I ...

Setting up an SSL certificate for an Express application: A step-by-step guide

I am currently trying to set up my Express server in order to pass the SSL certificate and transition from http to https. After going through the Express documentation, I still haven't been able to find a suitable solution. While some suggestions lik ...

The attempt to initiate the MongoDB server was unsuccessful. dbexit reported an error with code 48 within the MongoDB system

After updating MongoDB, I encountered an error. I attempted to restart the MongoDB service, but the error persists. ...

I encountered an issue when attempting to obtain the local issuer certificate for https://registry.yarnpkg.com

I encountered an error message stating unable to get local issuer certificate while trying to execute yarn add <anything>. Oddly enough, everything was working fine yesterday, but today this issue popped up seemingly out of nowhere with no recollect ...