Move the content of a specific section on a webpage without affecting the rest of the page in Selenium WebDriver

I'm encountering a challenge with nested scroll bars on Firefox while using Selenium Webdriver. My goal is to automate the functionality where scrolling down within a frame enables the Next button. I have attempted to use javascript executor, but it only scrolls the main page rather than inside the specific div. Additionally, my efforts with Actions have not been successful as seen in the code snippet below:

WebElement snapshot_list = driver.findElement(By.id("snapshots-list"));
Actions scrolldown = new Actions(driver);

scrolldown.moveToElement(snapshot_list).build().perform();
snapshot_list.click();

scrolldown.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform();

Although the TestNG reports show the test case passing without errors, the scrolldown.keyDown part seems to be skipped entirely. I would greatly appreciate any guidance or assistance in identifying what might be going wrong. Thank you.

Answer №1

This code successfully allowed me to scroll within the div:

WebElement assistanceInput = driver.findElement(By.id("abc"));
//Scrolling down the div until the element is visible
((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", assistanceInput);

assistanceInput.click();

Answer №2

You previously mentioned that you attempted to use the Javascript Executor, but did not specify all the methods you tried. If you have already tested the following options, please disregard them.

(((JavascriptExecutor)driver)).executeScript("document.getElementById('snapshots-list').scrollIntoView({ 
  behavior: 'smooth' 
});");

or

(((JavascriptExecutor)driver)).executeScript("document.getElementById('snapshots-list').scrollIntoView(true);");

or

(((JavascriptExecutor)driver)).executeScript("jQuery(\"snapshots-list\").mouseover();");

or click immediately after moving to element as described below

WebElement snapshot_list = driver.findElement(By.id("snapshots-list"));
Actions scrolldown = new Actions(driver);

scrolldown.moveToElement(snapshot_list).click().build().perform();

Answer №3

Success! I managed to solve the problem by using Actions and implementing a loop to check for a specific condition within the frame:

Actions action = new Actions(driver);
action.moveToElement(FirstSnapshot).build().perform();
FirstSnapshot.click();

while(Nextbutton.isEnabled()== false)
        {
        action.keyDown(Keys.CONTROL).sendKeys(Keys.DOWN).perform();
        }
System.out.println("Button is now enabled");

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

Steps to create a typewriter effect using a collection of words

I managed to create a looping typewriter effect, but I'm facing an issue where the first word in the array is not being typed again after the first cycle. Additionally, I am seeing 'undefined' displayed after the last word before it repeats ...

Is it necessary to make a distinct route for SocketIO implementation?

I am new to Socket.IO and I recently completed the chat tutorial in the documentation along with some additional tasks to gain a better understanding of how it works. Currently, I am attempting to establish a connection between a NodeJS server and a React ...

Tips for converting "module.exports" from JavaScript to TypeScript?

How can I transform the JavaScript concept of module.exports into TypeScript? The original JavaScript code with module.exports is shown below: module.exports = { discord: { clientID: "", clientSecret: "", cl ...

Alter the color of the dropdown background when it is changed

Currently, I am utilizing the Semantic UI React CSS library and find myself in need of changing the background color of dropdowns once an option is selected. https://i.sstatic.net/yZBK7.png to https://i.sstatic.net/LxTtT.png <Dropdown placeholder=&apo ...

Redux accesses the store data after a brief delay

I am new to using redux and I am currently working on implementing it for my very first project. Everything seems to be working fine, however, when I try to console.log the data from the redux store, initially it shows two empty arrays but in the subsequen ...

Analyzing elements within an array

I'm feeling a bit out of practice with my Java programming skills. I am working on creating a fictional company lottery where each employee is only allowed to enter once. The program will then randomly select a name to announce the winner. However, I ...

How should I handle Selenium when it takes longer due to the absence of a value in the dropdown menu?

I am in a situation where I need to select values from a drop-down list. However, in the current version, one item has been removed from the list. I have mentioned the name of the removed item in the code. When I run the Selenium script, it takes longer to ...

Personalize the Chrome webdriver with selenium for seamless file downloads without any prompts for saving or discarding files

I am facing an issue while trying to automate file downloads through selenium with Chrome as my browser and using chromedriver. Whenever I attempt to download .exe files, a prompt appears saying "This type of file can harm your computer, Discard or save it ...

In my SQL stored procedure, I tried using a cursor loop called `cursor_loop`, but it was only fetching one row instead of all 15

I'm having trouble fetching 15 rows in the cursor using this code. It only fetches one row instead of 15. Can anyone spot an error in the code? Any help would be greatly appreciated. Thank you in advance. delimiter $$ drop procedure if exists retrie ...

Is there a way to access the text from a text field?

After inputting text into the text field, I am having trouble retrieving the same value. Although sendKeys works fine, getText(), getAttribute, and JavascriptExecutor methods did not work for me. Below is the input HTML code provided: <input type ...

Error icon appearing on Material UI's Stepper Component when not needed

I am currently using the Stepper component from Material UI and attempting to make the fill of a stepper that is in its error state appear red. If you need to see the Stepper component from Material UI's documentation, you can access it https://i.sst ...

Assigning a variable in Vue.js after making a call with axios

One of the challenges I'm facing is trying to call axios using this.request(url) within a mixin. The goal is to streamline and consolidate all axios-related functionality in a single file, but I'm running into some issues. In my Vue file: expor ...

console rendering duplication in React

Why am I seeing duplicate log entries in the console? While working on another project, I noticed that the number of HTML elements being added using jQuery was twice as much as expected (specifically while building a notification framework). To investigate ...

Searching for partial text within several elements using Selenium - a comprehensive guide

Is there a way to search for partial text within the <p> elements of a web page that contain a specific string? I am able to locate full text, but not sure how to identify only a portion of the text if it matches a certain criteria. For instance, if ...

A guide on initiating a get request with URL in React

Utilizing React for the frontend and express for the backend has been my approach. By defining get methods in my express like this:- app.get('/addBill',(req,res)=>{ // --first method res.render("addBill"); }); app.get(&a ...

Can someone explain why Array.from(classList)[0] is not changing to 'className'?

HTML Design <div class="custom-container color-red"> <h3>Hello, I am a customized container</h3> </div> Javascript Logic let element = document.getElementsByClassName('custom-container')[0]; let clas ...

MixedUp Order in JSON

Whenever my application generates a JSON file, the updated content causes the order of elements to be mixed up. This leads to unnecessary differences showing in the diff even when the actual changes are minimal. Is there any way to maintain the original or ...

Do Java arrays follow pass by reference or pass by value?

Are arrays in Java passed by reference or by value? If we have an array named data containing objects of a certain type, and we pass this array to class A, which then passes it to class B where one of the entries is modified, will the version of the array ...

Getting older versions of Python Selenium Webdriver can be accomplished by searching for archives on reputable

Is it possible to remove Selenium Webdriver from a linux system? I am looking to revert back to version 2.33 which was more compatible with my setup. Could you provide me with instructions on how to install a specific version of Selenium on linux? On the ...

Parsing a JSON object with a missing value in one of its fields

Currently, I am facing an issue with deserializing a JSON object in the following format: public class Sample { private String x; private int y; private SubDataSample z; //additional fields, constructor, getters, etc } public class SubDataSample { ...