Is there a way to make selenium webdriver screenshot an entire page? - python

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.

Related

Python selenium right-clicking wrong elements

I am writing a program that answers questions from a database. I am currently on the last question type (ordering questions). Here is an image of what the question looks like. The user needs to put the elements in the box in order.
As you can see, the bottom of the question gets cut off. This caused errors when trying to click certain elements that were below the page. To try and solve this I scrolled to the bottom of the page but selenium scrolled back to the top before clicking which kept the error in place. And after trying a few other things I decided to try and zoom out on the webpage to see them all at once.
This is the HTML of the list where the <p> tag is what I am trying to click on. Actually, I am trying to right-click but same thing. The rest of the <div>s with the ellipses are the rest of the boxes and are the same as the first one.
newheader = self.driver.find_element(By.XPATH, "//div[contains(#class, 'responses-container')]")
action = ActionChains(self.driver)
action.context_click(WebDriverWait (newheader, 10).until(EC.presence_of_element_located((By.XPATH, "//p[contains(text(), '"+ dictionary_.get(prompt)[r] +"')]")))).perform()
# dictionary.get(prompt)[r] contains the values we are looking for (ovulation, fertilization, etc)
# I have also tried EC.element_to_be_clickable and had the same results
I have tested this on a question that does not overflow the page and it works perfectly. The only time I am getting errors is when I try to zoom out. I have tried refreshing the page before starting the clicking and after zooming out. I have also tried resetting the driver by calling
self.driver.get(self.driver.current_url)
Each of those elements cannot be left-clicked on to select. They can only be right-clicked or tabbed to. Tabbing requires calculations that are complex since each element is being moved dynamically so I chose to right-click instead. It does right-click but in seemingly random places now that it's zoomed out.
Any help is appreciated! Thanks!

How to move an internal HTML scrollbar using Selenium?

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

Multiple Scroll Bars in Python Selenium

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

Selenium WebDriver - Python - Simulate mouse scroll to the left/right using Selenium

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)

Taking screenshot of particular div element including the area inside scroll region using selenium and python

I need to take a screenshot of a particular given dom element including the area inside scroll region.
I tried to take a screen shot of entire web page using selenium and crop the image using Python Imaging Library with the dimensions given by selenium. But I couldnt figure out a way to capture the are under scroll region.
for example I have a class element container in my page and it is height is dynamic based on the content. I need to take screenshot of it entirely. but the resulting image skips the region inside scrollbar and the cropped image results with just the scroll bar in it
Is there any way to do this? Solution using selenium is preferable, if it cannot be done with selenium alternate solution will also do.
You can scrool with driver.execute_script method and then take a screenshot.
I scroll some modal windowns this way with jQuery:
driver.execute_script("$('.ui-window-wrap:visible').scrollTop(document.body.scrollHeight);")

Categories

Resources