Enhance your automation with the powerful combination of Java,

I am looking to retrieve data from a specific Russian gambling website using String information. Below is the code I have written for this purpose:

 import org.openqa.selenium.JavascriptExecutor;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.firefox.FirefoxOptions;
    import java.util.concurrent.TimeUnit;
    
    public class Main {
        public static void main(String[] args){
            FirefoxOptions options = new FirefoxOptions();
            String userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36 OPR/60.0.3255.170";
            System.setProperty("webdriver.gecko.driver","C:\\Users\\dbondarenko\\IdeaProjects\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        JavascriptExecutor js = (JavascriptExecutor)driver;

        String baseUrl = "https://parimatch.com/ru/events/romania-iceland-6764586";

        driver.get(baseUrl);

        driver.manage().window().maximize();

        driver.manage().timeouts().setScriptTimeout(20, TimeUnit.SECONDS);

        String DomainName = js.executeScript("return document.domain;").toString();
        System.out.println("Domain name of the site = " + DomainName);

        String url = js.executeScript("return document.URL;").toString();
        System.out.println("URL of the site = " + url);

        String TitleName = js.executeScript("return document.title;").toString();
        System.out.println("Title of the page = " + TitleName);

        String innerText = js.executeScript(" return document.documentElement.innerText;").toString();
        System.out.println("Inner text of the page = " + innerText);

        js.executeScript("window.location = 'http://parimatch.com'");
    }
}

The output I'm receiving contains some correct information, but it also includes many ellipsis signs instead of the exact output I need. Despite trying various solutions, I remain puzzled about how to resolve this issue. The page URL can be extracted from the code. Here is an example of my output:

Domain name of the site = parimatch.com
URL of the site = https://parimatch.com/ru/events/romania-iceland-6764586
Title of the page = Ставки на - . . . . - в БК Parimatch
JavaScript warning: https://parimatch.com/fpapi/s.js, line 1: WEBGL_debug_renderer_info is deprecated in Firefox and will be removed. Please use RENDERER.
JavaScript warning: https://parimatch.com/fpapi/s.js, line 1: WEBGL_debug_renderer_info is deprecated in Firefox and will be removed. Please use RENDERER.
JavaScript warning: https://promo.parimatch.com/api/adpool/static/adp.js, line 113: WEBGL_debug_renderer_info is deprecated in Firefox and will be removed. Please use RENDERER.
Inner text of the page = ...
...
...
...
...
...
...
Топ
Топ Экспрессы (and so on)

Answer №1

Using the JavascriptExecutor in Selenium to extract the innertext involves executing the following lines of code:

String innerText = js.executeScript(" return document.documentElement.innerText;").toString();
System.out.println("Inner text of the page = " + innerText);
    

The innerText is retrieved immediately through JavaScript calls even before all text is rendered in the HTML DOM, resulting in blank spaces.

Instead, if you manually check from the console using the command:

document.documentElement.innerText

You will see the output as shown here:

https://i.sstatic.net/ogzDa.png


Solution

To resolve this issue, include some wait time and then execute the relevant lines of code, for example Thread.sleep(5000). This will give you the complete expected output.

(previously included large block of text removed for space considerations)

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

Guide on creating a function that accepts an Array of strings as a parameter and displays the initial letter of each element individually on separate lines

I am currently tackling my initial JavaScript assignment which involves the task of creating a function that accepts an array of strings as its parameter and outputs the first letter of each element individually on separate lines. The unique requirement ...

Re-establishing the socket channel connection in a React application after a disconnection

There are several solutions to this issue, but none of them seem to be effective for me. The existing solutions are either outdated or do not meet my needs. I am facing a problem where I have a large amount of data being transferred from the server to the ...

What is preventing me from altering the array one element at a time?

I am working with an array and a class let questions = [ { questionText: '', answerOptions: [], }, ]; class Questions { constructor(questionText,answerOptions) { this.questionText = questionText; this.answerOptio ...

Transferring information from an Arduino board to Java

I am currently working on a personal project involving RFID cards. I am trying to send an RFID code (cardID) to my Arduino and then scan a random RFID card. If the sent RFID code and the one scanned match, I want to send back a string, number, or just one ...

What is causing it to give me 'undefined' as the result?

Trying to execute a script, test.al(); and within test.al, it calls getcrypt.php();. The php script is hosted on a webserver, and it is functioning properly. Here are the current scripts being used: JS var getcrypt = { php: function () { $.a ...

Using a React button to sort through an array

Hey there, I'm currently working on an app that filters a list based on user input. The idea is to click on buttons to exclude users with specific letters in their names. However, the code I have right now isn't functioning properly. Any assistan ...

Learn how to effectively share an image using the Math.random function

Is there a way to display a random number of images on a webpage using JavaScript? Let's say we want to show X number of images, where X is a randomly generated number. For the sake of this example, let's set X to be 10. <input class="randomb ...

The use of a <button> element in a React App within a Web Component with Shadow DOM in Chrome disables the ability to highlight text

An unusual problem has arisen, but I have a concise example that demonstrates the issue: https://codesandbox.io/s/falling-architecture-hvrsd?file=/src/index.js https://i.stack.imgur.com/CkL4g.png https://i.stack.imgur.com/nDjuD.png By utilizing the divs ...

Exploring data elements using iteration in JavaScript

Here is some code that is functioning properly: Morris.Bar({ element: 'barchart', axes: true, data: [ json.bar.bar1 ], xkey: 'x', ykeys: ['y', 'z', ' ...

Leverage the NextRouter functionality without the need for a React component

I've created a custom hook that checks if a user is logged in and redirects them to the login page if not. Below is a simplified version of the hook assuming the user is not logged in: import { useRouter } from 'next/router'; export default ...

Sending information from a directive to a controller

I'm working on passing a resource from a directive scope to a controller scope by utilizing a callback provided in the view. However, I'm encountering an issue where the argument variable is showing as undefined. Can you help me figure out what I ...

The type 'Event' argument cannot be assigned to the 'InfiniteScrollCustomEvent' parameter

I'm facing an issue with Ionic Angular. Here is my movies.page.html: <ion-header> <ion-toolbar color="primary"> <ion-title>Trending Movies</ion-title> </ion-toolbar> </ion-header> <ion-content ...

Storing data or a page in a list within a React Native application

As a newcomer to React Native, I'm facing an issue. I have two pages called rockSetting.js and myFavoriteSetting.js. In the rockSetting page, I want to implement an onButtonPress function that will generate a list in the myFavoriteSettings page with ...

Deactivate certain days in Material UI calendar component within a React application

Currently, my DatePicker component in React js is utilizing material-ui v0.20.0. <Field name='appointmentDate' label="Select Date" component={this.renderDatePicker} /> renderDatePicker = ({ input, label, meta: { touched, error ...

Display React elements on the web page

Seeking assistance from anyone! I've been grappling with a problem and can't seem to figure out a solution. Here's the scenario: My current setup involves a sidebar and a top bar for navigation in React. Check out my app so far in this imag ...

Error encountered in amCharts Serial Chart when data parsing is enabled with the setting "parseDates": true which resulted in the failure to display data

Using Spring as a webservice, I received a JSON response with stock data: [ { "date": "2016-04-17", "open": 1085.0, "high": 1092.2, "low": 1072.0, "close": 1088.3, "volume": 54100, "value": 1088.3 }, { "date": "2016-04-14", "open": 1081. ...

Utilize the power of both $push and save functions in MongoDB for efficient

While developing my pet application, I encountered a problem. I am using nodejs and the mongojs library to interact with MongoDB. The code I wrote goes like this: db.users.findOne({_id: ObjectId(id)}, function (err, doc) { if (err) { res.sta ...

Javascript favorite star toggling

An excellent illustration is the star icon located on the left side of this post. You have the ability to click on it to save this message as a favorite and click again to remove the flag. I have already set up a page /favorites/add/{post_id}/, but I am ...

Extending Two Classes in Typescript: A Complete Guide

I am looking for a way to efficiently save time by reusing common code across classes that extend PIXI classes within a 2D WebGL renderer library. Object Interfaces: module Game.Core { export interface IObject {} export interface IManagedObject e ...

HTML: Ensure that a user fills out a minimum of one text box before submission

<tr><td> First Name: </td><td><input type="text" name="FirstName" required></td> </tr> <tr><td> Last Name: </td><td><input type="text" name="LastName" required> </td></tr> ...