I would like to scrape a webpage where in the main page there are 2 scroll bar. I can scroll down main scroll. But how can i scroll left side? i will attach a screenshot, because it is hard to explain it with words.
you can see that there 2 scroll in the picture. i would scroll left side with using selenium webdriver. How can i do this?
You can execute JavaScript code that's scrolling the page to specific X, Y and change the X (the Y is height).
Execute it like that:
driver.execute_script('window.scrollTo(X, Y)')
Just replace the X and Y for your scrolling values.
Example:
driver.execute_script('window.scrollTo(200, 0)') # It'll scroll to 200 left-position and also scrolling to 0 top-position.
You can use this JsExecutor script to scroll to the needed element:
driver.execute_script.execute_script("arguments[0].scrollIntoView(true);", element);
Related
I am using Selenium + Python to scrape this site. I am interested in getting the information out of the Power BI table, which I can currently do using Beautiful Soup. My problem is that only the cells that are currently in view are loaded on the page. The rest are loaded as the table is scrolled, which can only be done if the mouse is over the table (in other words, this driver.execute_script('arguments[0].scrollIntoView(true);', target) doesn't work) or if the scroll bar is dragged downward. The code I am currently using tries to find the scrollBar element, click-and-hold, and drag it down some number of pixels to load another set of cells.
scrollBar = driver.find_element_by_class_name("scroll-bar-part-bar")
webdriver.ActionChains(driver).move_to_element(scrollBar).click_and_hold(scrollBar).move_by_offset(0,30).release().perform()
It kinda seems like the "mouse" isn't in the correct place when it clicks and holds. Is there a more straight forward was of doing this? I have tried simulating a mouse wheel scroll from this answer, but I am not able to get that to work either.
use:
driver.execute_script("arguments.scrollBy(0,arguments[0].scrollHeight)",scrollBar)
This scrolls the element, you should do scroll on the scroll bar element
I would like to know if there is any way to scroll down and also click on buttons at the same time.
For example Instagram. When you click on account 'follow' there is a pop up with images, text, and buttons.
There is any way to scroll and mean time to do other stuff?
For example, scroll down and click on the 'Follow' button while it's scrolling down.
Now I'm just using this code driver.execute_script("""arguments[0].scrollTo(0, arguments[0].scrollHeight); return arguments[0].scrollHeight;""", element)
Which is good, BUT it first scrolls all the way down, and when it finishes then I can do whatever I want to. Which is not the solution I'm looking for.
Any tips guys?
I'm using Chrome driver
I want to scroll the left nav bar (which shows the job list) to the bottom using python, selenium and chromedriver. I tried using:
_driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
But nothing happened. I'm new to web automation, please let me know if you need anything.
P.S. Page source
This is the last element job list in the left nav bar:
(//li[contains(#class, 'PaEvOc')])[last()]
To achieve scroll to bottom left nav use .location_once_scrolled_into_view:
element = driver.find_element_by_xpath("(//li[contains(#class, 'PaEvOc')])[last()]")
element.location_once_scrolled_into_view
In the my test-app that's built in angular there is a table with no scrollbar containing 10-11 columns. In the default view, there would be 8 fields displayed. To view the rest of fields, the user has to either use the mouse scroll to the right to view the fields/ use keyword arrow buttons. I need to simulate this in selenium webdriver to scroll to the 11th column so that I can perform further validations. I tried to use scrollintoview function in javascript. However, since the element is not displayed without scroll, it does not work. Please note that the html table do not contain any veritical/ horizontal scrollbars.
You can give a try with this.
javaScript = "document.getElementById('any_visible_locator').scrollLeft += -250;"
driver.execute_script(javaScript)
The title is pretty self explanatory. I have a page with an iframe and two columns (left and right)
Left has no scroll bar, while right has a scroll bar with a total of 600px to scroll. I need to screenshot the entirety of the right hand column. It doesn't matter if I get the entire page or not, as long as everything in the right hand column is in the screenshot.
I am using Selenium 2 Webdriver + python
There is workaround by following the steps described in http://www.ramandv.com/blog/angularjs-protractor-selenium-headless-end-end-testing/ and create a gaint virtual display for running your program.