I am in need of capturing a screenshot of a specific URL using chromedriver and

Is there a way to capture a screenshot of a website based on specified screen size, pixels, or by performing scroll up and down operations? I need to do this similar to using the snipping tool. Can anyone provide me with a solution to achieve this using the following URL?

This is the code snippet I am currently using in AWS Lambda:

import json
#coding=utf-8                                                                                                                                                                              
import time
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
import logging
import os

class WebDriver(object):

    def __init__(self):
        self.options = Options()

        self.options.binary_location = '/opt/headless-chromium'
        #self.options.add_argument('--headless')
        self.options.add_argument('--no-sandbox')
        #self.options.add_argument('--start-maximized')
        #self.options.add_argument('--start-fullscreen')
        self.options.add_argument('--single-process')
        self.options.add_argument('--disable-dev-shm-usage')
        self.options.add_argument("--kiosk")

    def get(self):
        driver = Chrome('/opt/chromedriver', options=self.options)
        return driver

def lambda_handler(event, context):
    instance_ = WebDriver()
    driver = instance_.get()
    options = Options()
    a = os.listdir('/tmp')
    for x in a:
        print(x)
    URL = os.environ.get("URL")
    
    driver.get(URL)
    
    S = lambda X: driver.execute_script('return document.body.parentNode.scroll'+X)
    #driver.set_window_size(S('Width'),S('Height'))
    #driver.set_window_size(1280, 720)
    # May need manual adjustment                                                                                                                
    driver.find_element_by_tag_name('body').screenshot('/tmp/job_status.png')
    
    driver.quit()

https://i.stack.imgur.com/VH13q.png

Answer №1

Utilizing xpath to retrieve a specific division within the class.

driver.find_element_by_xpath('/html/body/div/div[1]/section[2]/div[1]/div/div[2]').screenshot('/tmp/daily_job_status.png')

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

Currently caught up creating an Instagram bot

Here is the code snippet I have been working on: import time from selenium import webdriver from selenium.webdriver.common.keys import Keys # initiating browser session browser = webdriver.Chrome() browser.get("https://instagram.com") time.sleep ...

I am seeking recommendations for the appropriate xpath to use with the following HTML code

<div class="alert ui-pnotify-container alert-warning ui-pnotify-shadow" style="min-height: 16px;"><div class="ui-pnotify-closer" style="cursor: pointer; visibility: hidden; display: none;"><span class="glyphicon glyphicon-remove" title="Clos ...

JavaScript code to retrieve an image from an <img> tag's source URL that only allows a single request and is tainted due to cross-origin restrictions

I have an image displayed in the HTML DOM. https://i.stack.imgur.com/oRgvF.png This particular image (the one with a green border) is contained within an img tag and has a URL as its source. I attempted to fetch this image using the fetch method, but enc ...

What is the best way to extract text from a div element?

I'm attempting to extract text from a div and save it in a text document using Selenium with C#. I'm facing an issue where I can't retrieve the text from the div and store it in a variable. <div data-tid="messageContent" dir="auto">&l ...

Discovering the method for retrieving JavaScript output in Selenium

Whenever I need to run JavaScript code, the following script has been proven to work effectively: from selenium import webdriver driver=webdriver.Firefox() driver.get("https:example.com") driver.execute_script('isLogin()') However, when I atte ...

Tips on how to incorporate information into variables in cucumber's feature files?

Currently tackling a UI selenium project where the goal is to extract String data from the UI and convert it into a variable within my .feature scenario file. In order to illustrate, let's take an example where I only have access to the customerID: ...

Having trouble inputting text into a numerical field with Selenium in Java

I am facing a challenge while testing an input field on a form using Selenium. The form input is of type number with the following attributes: <input required type="number" class="form-control" id="number" name="number" placeholder="Number" step="1" mi ...

python-selenium clicking on specific coordinates: "error when adding different types"

I'm having an issue with my automated tests on Robot Framework where I need to click on specific coordinates on a map. Here is the code snippet that I wrote: def click_at_coordinates(pos_x, pos_y): actions = ActionChains(get_driver()) my_map ...

PhantomJS with Selenium encounters ElementNotVisible error when selecting a combo box, whereas Firefox performs without any issues in the same

I am working on a website that features a unique combo box where items are selected from divs instead of traditional options. My program needs to click on the combo box, wait (I've found using implicitly_wait(3) for 3 seconds works best), and then sel ...

Unable to identify the unsuccessful test case

When executing my test cases using Selenium and NUnit, I encounter an issue with saving screenshots. The goal is to save the screenshot in a "Pass" folder if the test case passes, and in a "Fail" folder if it fails. However, currently only passed test case ...

Tips for adding an attribute to an XPath query

Currently, I am utilizing selenium to navigate through various pages. Here is an example of the page source: <td colspan="10" align="right"> <input type="button" name="previous" value="Previous" onclick="this.form.action = 'c ...

Utilizing the power of Python with Selenium Webdriver to effortlessly upload an image onto Google's image

from selenium import webdriver from selenium.webdriver.common.keys import Keys import sys, os from time import sleep class imageSearch(): """ Image search automation using Google reverse image search with Selenium and Python 3.8. Dependencies: ...

"Receiving an error that Element cannot be clicked at a specific point in Chrome while using Webdriver

There's a well-known bug that I've been trying to avoid in three different ways: checking for overlapping elements, setting sleep time for complete page download, and verifying element visibility. Despite my best efforts, none of these methods se ...

Dynamic button on dialog box could not be found

When I click on the search button, I am having trouble locating a dynamic button element. The Create Account CID is sometimes clickable and sometimes not. <div class="pzbtn-rgt" data-click="..."> <div class="pzbtn-mid" data-click="...."> < ...

Seeking assistance with adding information to a list that currently has no data stored

I have recently started coding and decided to scrape the Indeed website for job listings. Using selenium's find_element function, I successfully scraped job titles, company names, and locations. Now, I'm seeking guidance on how to store these ind ...

Suggestions for content in Jenkins Execute shell script for running automated tests

I'm a beginner with Jenkins and I'm unsure about what to enter in the Build - Execute shell script section. I want to run my automation scripts using Jenkins. I write my scripts in Selenium WebDriver and use macOS. Can someone provide me with a d ...

An incomplete Xpath query results in a null value

I have an element with ID=Mscrm.BasicHomeTab.New.NewRecord When I attempt to find the element using the query below, I am successful: FindElement(By.XPath("//*[@id='Mscrm.BasicHomeTab.New.NewRec‌​ord']")) However, if I try to locate the el ...

Ways to loop through xpath and verify image existence before executing specific actions

View Image Examining the image provided reveals two solutions: one for a flight and the other for a hotel. The objective is to iterate through each solution using XPATH. Success has been achieved in this aspect. The goal now is to verify the returned ima ...

Using BeautifulSoup to scrape a URL and generate a list of link addresses

Seeking insights on website similarity, I aim to extract data from the following link: Focusing on class='site', my goal is to retrieve information like: <a href="/siteinfo/ebay.com" class="truncation">ebay.com</a> ...

The DefaultWait<T> method utilizes a combination of ExpectedConditions OR AND AND for better

When utilizing C# with Selenium webdriver, I navigate to a webpage that may either redirect to a login screen or directly to the application page based on whether cached credentials are present (such as in the case of azure active directory authentication) ...