Tips for automating dialog box scroll with selenium in Java

I'm attempting to automate the Instagram website, but when I click on the followers link it opens a dialog box with users to follow. However, when I try to scroll within that dialog box, it ends up scrolling the main page rather than the followers dialog box itself. Any suggestions on how to make this work?

Below is the code snippet I used:

WebElement element = driver.findElement(By.cssSelector("div.pbNvD.fPMEg.HYpXt"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0,1000)",element);

Answer №1

Here are two different ways you can scroll to the top:

WebElement element = driver.findElement(By.cssSelector("div.pbNvD.fPMEg.HYpXt"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].scrollTop(100)",element);

or

js.executeScript("$('div.pbNvD.fPMEg.HYpXt').scrollTop(100)");

Answer №2

If you want to scroll a modal dialog down, you can use the following code snippet:

// Check for the visibility of the modal
WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOfElementLocated(By.id("document-content")));
// Find the last child element within the content div
WebElement lastChild = driver.findElement(By.xpath("//div[@id='document-content']/*[last()]"));
// Scroll the page to bring the last child into view
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", lastChild);

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

Conceal the page's content as it moves beneath a stationary div

My issue involves a fixed div position with a margin from the top of the page. When I scroll my page, the content of my relatively positioned div (containing page content) is visible under the fixed div due to the margin from the top of the page. Despite s ...

When iterating through an array in Java using a loop, the iteration starts back at field 0 once it reaches the last field

Exploring the comparison logic between the header fields of a CSV file read by a BufferedReader (highlighted in yellow, see screenshot below) and the fields of the specified array: static String[] HEADER_VALUE = {"Time", "Table Accel X&q ...

The hidden div is revealed by selenium IDE and promptly hidden again

I am encountering an issue with a hidden div element in my Selenium IDE script. Upon clicking the link, the visibility of the div changes as expected. However, I have noticed that the div opens briefly and then immediately closes. While the rest of the scr ...

Update the styling of buttons in CSS to feature a unique frame color other

Can anyone help me with styling Bootstrap buttons and removing the blue frame around them after they're clicked? Here's what I've tried: https://i.stack.imgur.com/jUD7J.png I've looked at various solutions online suggesting to use "ou ...

Leverage openpyxl for exporting outcomes into an Excel workbook

I've been working on using openpyxl to generate some Excel output, but I haven't been successful so far. I'm not exactly sure where I'm going wrong. Can anyone provide some insight on this? Thank you. from selenium import webdriver imp ...

Remove the image element within the grid once an object has entered the grid

I've been diving into game programming and am currently working on developing a game similar to Pacman. In order to create the game grid, I've implemented x[] and y[] arrays instead of using tiled. I'm facing an issue where I need to destroy ...

Tips for aligning the text in a navigation bar to the center

My CSS skills are not very strong. How can I center the text "My Website" in my navbar based on this code? You can view a working example on JSFiddle here: https://jsfiddle.net/cvp8w2tf/2/ Thank you for your assistance! ...

Change a div to scroll vertically instead of expanding to accommodate its content

I am facing an issue with the layout I have created. It consists of a scrollable list of items in the center, with additional content above and below it in a column. The challenge is to make the list occupy all available empty space within the column witho ...

Conceal all elements until a search query is entered using the search bar

I want to create a search bar that hides all elements until the user actually searches for them, you can check out my JSfiddle for reference: `JSfiddle Link <div id="search"> <form> <input type="text" name="search" id="m ...

Guide to emulating a web page button click with Python

Having trouble scraping a website that requires a user to click a button? You're not alone. Even with Selenium, finding the right button can be tricky. Take a look at the HTML of the webpage before the click: <div id="startStopBtn" onclic ...

Executing test cases within the TestNG framework

Hey there! I'm currently facing an issue while running a test case in TestNG. I need to generate reports and track the number of failed and passed test cases. The code below works perfectly fine when executed in a regular Java class... @Test public v ...

Unusual scroll bar movements when using jQuery validation

When I click the Add Dependent link button, I wanted the scroll bar to automatically scroll to the bottom, and it does just that. However, there is a small issue after the postback where the text "Please fix the following problems:" briefly appears, even t ...

Arrange four Divs next to each other with flexbox styling

I've been struggling with aligning my cards side by side. They are a series of divs nested in lists under a <ul> Changing the positioning is not resolving the issue, and I'm hesitant to alter the display as it's crucial for responsive ...

The local() function in CSS @font-face is limited to finding only the "regular" and "bold" font styles, not others

Recently, I added some new fonts (specifically Roboto) to my Linux Ubuntu PC and wanted to incorporate them into my CSS using the @font-face rule. However, I encountered an issue when specifying different font weights within the src: ; property as shown in ...

A guide to using JavaScript to create a button that can dynamically change stylesheets

Just a heads up, I'm not using classes in this particular scenario. Can't seem to find the answer to this exact question. With javascript, how can I code a button to switch stylesheets every time it's clicked? I've experimented with d ...

How to visually deactivate a flat button ( <input type="button"> ) programmatically with JavaScript

I am facing an issue with my buttons. I have one regular button and another flat button created using input elements. After every click, I want to disable the buttons for 5 seconds. The disable function is working properly for the normal button, but for th ...

What is the mechanism through which a flexbox enlarges to accommodate its overflowing child elements?

I am working with a flexbox layout. Here is the HTML code structure: <div class="grid"> <div class="row"> <div class="column">Content</div> <div class="column">Content2</div> <div class="column">Con ...

CSS Trick: Applying first-of-type selector to specific instances of a div

I'm currently grappling with how to specify that a 'first-of-type' should only be present on specific instances of a div. For instance, suppose I have a class called ".maintext" and in some cases I want the first paragraph to feature a dropc ...

How can I delete a hyperlink on a number from my iPhone or iPad?

Is there a way to prevent certain sets of numbers from being linked, like phone numbers do on iPhones? <h2>Table</h2> <table class="table table-sm table-striped table-hover"> <caption class="sr-only">Search Results</caption> ...

Using jQuery or Javascript to enclose every character in a given string with an HTML tag

I am trying to create a function that can take a string of text and wrap each letter within that string with an HTML tag such as <i> or <span>. Although I have made some progress, the current solution is not working as expected. The issue I a ...