Steps for obtaining images using lazy loading: <img loading="lazy"

After successfully utilizing the JavaScript-executer to locate the ImageElement, I encountered an error when attempting to extract the URL for downloading the image.svg. The error message reads "NoSuchElementException." Below is a snippet of my code:

((JavascriptExecutor)driver).executeScript("window.open('https://www.lambdatest.com/selenium-automation/','_blank');");                     
wait.until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));         
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));  
JavascriptExecutor js = (JavascriptExecutor) driver;   

By Image=By.xpath("//img[@title='Jenkins']");            
js.executeScript("window.scrollTo(0, document.body.scrollHeight)");           
      //  The commented-out section below results in an Error 
/*WebElement ImageElemnt =driver.findElement(Image); 
   String src = ImageElemnt.getAttribute("src");    
    System.out.println(src);*/



wait.ignoring(NoSuchElementException.class).until(ExpectedConditions.invisibilityOfElementLocated(Image))

Answer №1

Issue Explanation :

Your code starts off with

((JavascriptExecutor)driver).executeScript("window.open('https://www.lambdatest.com/selenium-automation/','_blank');");  

This line essentially attempts to open

https://www.lambdatest.com/selenium-automation/
in a new tab. However, Selenium won't automatically switch to the new tab unless you explicitly command it to.

To handle this situation correctly, your code should look something like this

((JavascriptExecutor)driver).executeScript("window.open('https://www.lambdatest.com/selenium-automation/','_blank');");  
ArrayList<String> tabs2 = new ArrayList<String>(driver.getWindowHandles());
driver.switchTo().window(tabs2.get(1));

Update 1 :

((JavascriptExecutor)driver).executeScript("window.open('https://www.lambdatest.com/selenium-automation/', '_blank');");
ArrayList<String> tabs2 = new ArrayList<String>(driver.getWindowHandles());
driver.switchTo().window(tabs2.get(1));
Thread.sleep(5000);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//img[@title='Jenkins']")))
js.executeScript("arguments[0].scrollIntoView(true);", element);
String source = element.getAttribute('src')
System.out.println(source);

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

Encountering a java.lang.NoSuchFieldError: Companion error while using the okhttp3 library in conjunction

In my project, I am utilizing Retrofit2 and Okhttp for making HTTP calls along with Selenium. Recently, upon adding the below dependency: <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>logging-i ...

Is it possible to utilize AJAX to load the URL and then extract and analyze the data rather than

I had originally created a web scraping method using PHP, but then discovered that the platform I was developing on (iOS via phone gap) did not support PHP. Fortunately, I was able to find a solution using JS. $(document).ready(function(){ var container ...

Monitor a nested watch property for potential undefined or default values

Currently tackling an issue in my Vue2 project related to a specific property I'm trying to watch. Here's what the code snippet looks like: watch: { 'car.wheels': function(){ ... } Sometimes, 'wheels' is undefined ...

Understanding the Vue lifecycle methods for updating Vuex state

Utilizing Vue and Vuex components, the code within my component consists of: computed: { ...mapState({ address: state => state.wallet.address }) }, The functionality operates smoothly in the user interface. However, my objective is to invoke a ...

Is there a way to clear the list after each input is made?

Looking for help with the Ping Pong Test. Whenever I click Start and enter a number, it just keeps adding to the list. How can I make it reset the list after each input? $(document).ready(function() { $("#Start").click(function() { ...

Identify when 2 sets of radio buttons are chosen using jQuery

I need assistance with a webpage that presents the user with two simple yes-no inquiries. Below each question, there are two radio buttons for selecting either yes or no. <p>Question 1: Yes or No?</p> <input type="radio" name="q ...

Error Message: Undefined Constructor for Firebase Google Authentication

Hey there! I've been working on integrating Firebase google authentication into my project. Unfortunately, I encountered an error while testing it out. Here's the error message that appeared in the console: Uncaught (in promise) TypeError: Cannot ...

Exploring the Capabilities of Drag-and-Drop Functionality in jsTree and DataTables

Is it possible to copy nodes from a jsTree that I've dragged to a cell in a DataTable? I'm struggling with getting this functionality to work. Any suggestions on how to achieve this? I am not seeing any alerts appear. This is the HTML code: &l ...

What does the use of square brackets signify in Vuex mutations?

I'm curious about the use of mutation values within brackets in Vuex. What does the code "" represent? export const SOME_MUTATION = 'SOME_MUTATION' Is this just a constant name for a function? If so, why is it enclosed in brackets "[]"? ...

Utilizing Selenium in Python to Extract Links and Background Images from Specific Div Elements

I am attempting to retrieve all the links and background images of the links within a specific div, but I am encountering difficulties. My goal is to extract the links and background images from the paint_wrap div, not the paint_color. Here is the HTML s ...

The outline color cannot be removed from vue-carousel

I recently downloaded the Vue Carousel library and here is the version I am using: "vue": "^2.6.11", "vue-carousel": "^0.18.0", When I click on the pagination, a focus effect is added to the element with an outlin ...

What is the best way to use Selenium with Python to activate a button element?

Recently, I delved into using Selenium for Python and encountered a challenge when attempting to click on a button element nested within multiple div elements. Despite trying numerous approaches, the final step of waiting for the button to become clickable ...

Challenges with synchronizing Highcharts horizontally

I have been working on implementing synchronized charts in my application by using the example code provided by Highcharts here. My layout consists of columns created with the Materialize framework, and I placed the charts side by side in a row. However, I ...

What would be the best way to structure this workflow as a JavaScript data format?

I have a complex workflow that I need to represent as a JavaScript data structure. This workflow involves a series of questions and answers where the response to one question determines the next one asked. Here is a basic example of what this workflow migh ...

Having trouble sending a function as a prop to a child component in React

Something odd is happening, I'm confident that the syntax is correct, but an error keeps popping up: Error: chooseMessage is not a function // MAIN COMPONENT import React, { useState } from 'react' export default function LayoutMain(prop ...

The Angular Material layouts demonstration is experiencing technical difficulties

I'm attempting to run the Angular Material grid layouts demo titled Flex Percent Values, which can be accessed here. Here are some snippets from my HTML code: <head> <meta charset="UTF-8"> <meta name="viewport" content="initial-sc ...

Is ng-repeat failing to bind values in the Dom?

When loading data dynamically to ng-repeat, I am encountering an issue where the data is not binding to ul. Typically, this can happen with duplicate indexes, but in my case I'm unsure of what's causing it. Any suggestions? main.html <div> ...

Resolving the Table Issue with 'onclick' in Javascript

Apologies for the lack of creativity in the title, I struggled to come up with something fitting. Currently, I am engaged in the development of a user-friendly WYSIWYG site builder. However, I have encountered an obstacle along the way. I've devised ...

How do I pass input values when calling an AJAX function to submit a form in HTML?

Utilizing a modal to submit new data via AJAX API consumption. Although sending the data through the API is not an issue, my lack of HTML skills makes it confusing on how to pass form data values. This scenario involves displaying a modal for users to in ...

Creating a React functional component that updates state when a specific window breakpoint is reached

Having an issue with my code when it hits the 960px breakpoint. Instead of triggering once, it's firing multiple times causing unexpected behavior. Can someone help me troubleshoot this problem? const mediaQuery = '(max-width: 960px)'; con ...