Capturing selenium screenshots and showcasing them on a tkinter graphical user interface (GUI

I'm attempting to capture a screenshot of a page using selenium and display it on a canvas in my tkinter interface. However, I keep encountering the following error:

TypeError: __str__ returned non-string (type bytes)

Here is the code snippet. Any assistance would be greatly appreciated.

from tkinter import *
import tkinter as tk
import time
from selenium import webdriver

root = tk.Tk()
root.geometry('700x700')

def picture():
    browser = webdriver.Chrome('C:\\Users\\Downloads\\chromedriver_win324\\chromedriver.exe')
    browser.get('https://google.co.uk')
    fil = browser.get_screenshot_as_png()
    img = PhotoImage(fil)
    canvas = Canvas(root, width=300,height=300)
    canvas.place(x=12.5,y=450)
    canvas.create_image(20,20, image=img)

Button(root, text='Start', command=lambda: picture()).pack()
root.mainloop()

Answer №1

One issue arises when attempting to utilize the data as the primary positional parameter for PhotoImage, whereas the first positional parameter should be designated for the name instead of the image content.

The correct approach involves assigning the data as the input for the data attribute:

image = PhotoImage(data=file_data)

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

Retrieving data using the Chrome WebDriver

I am facing an issue with retrieving data from a URL via download. The code provided below is functional in some cases on the specific website, but in other instances, it opens the browser, goes to the site, and then nothing happens. Despite trying differe ...

Adding a variety of variables to CSV document

Although this may seem similar to a previous question I asked, I have a Python code where I am analyzing the tone of text/html files and saving the output to a CSV file. My current issue is that I need to include two variables from the output, 'Tone_n ...

concealing your password within a Java class file as part of a testing scenario

I am currently developing a Selenium test case for our company's Jenkins server, where all employees have access to view the Java files I create. public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.get(" ...

Using PhantomJS webdriver in Python during an ssh session results in issues with user input

When running my Python program remotely with a PhantomJS webdriver, I encountered an issue where user input was not responsive most of the time. Despite everything executing smoothly when run locally, the majority of keypresses did not register at a prompt ...

What is the method for choosing a hyperlink based on its text content?

Greetings all, I am in search of a method to utilize the selenium Chrome web driver for clicking on a link within a table that is deeply nested in a webpage. The page consists of a main section in the center, with a navigation menu on the left for applica ...

Exploring the World of GUIs with Python's Tk

I am in search of a helpful resource to guide me on how to connect TKinter with JSON. I would like to input a word, search for that word in the JSON file, and then display the result of the search. Currently, I have my python application running smoothly ...

The PyQT5 ui file fails to load correctly when running the executable

Currently, I am in the process of developing a PyQt5 application using the designer to create interfaces and then exporting them as .ui files. These files are subsequently loaded by my primary class. Below is an excerpt from my code snippet, named main.py: ...

The command driver.quit() triggers an error in Firefox, causing the browser to crash

When the driver.quit() method is called, it causes Firefox to stop working. Although the tests do not fail, every time driver.quit is executed, the browser crashes as seen in the image below. This is my code snippet: public void quitDriver() throws E ...

Executing a click action with Watir WebDriver that does not require waiting for the page to fully load

My webpage has a unique feature where one side refreshes when a button is clicked on the other side. I am curious to see if the site will malfunction if I click the buttons too quickly, not allowing enough time for the right side to fully load. Currently, ...

Guide to downloading a file using Python, Selenium, and PhantomJS

I am currently facing a challenge where I need to login to a website and download a CSV file from a Linux server in a headless manner. The webpage utilizes JavaScript and is dependent on it for functionality. After conducting some research, I decided to u ...

Selenium Mouse/Pointer Display

Is there a way to visualize the selenium mouse movements during test execution? Can we display a windows cursor image or any kind of indicator like a dot or crosshair? I am currently working on implementing a drag and drop feature using Selenium and Java ...

Element could not be found inside the pop-up dialog

I have been attempting to find those buttons displayed here: https://i.stack.imgur.com/5M1qd.png Here is the HTML for them: https://i.stack.imgur.com/238no.png I've experimented with different methods, but unfortunately, nothing has succeeded. ...

Python can be used to extract data from Highcharts through scraping techniques

I have been attempting to extract information from the chart located at . I made an effort to gather the data by utilizing the corresponding XPaths for the data in the sections, but unfortunately, it was not successful. I experimented with using Scrapy: d ...

Storing a collection in redis-py

Attempting to save a list created from a dictionary into my redis database, I am running the following script: x = {'TLV-IST#2022-12-27~2023-01-04': '252', 'TLV-IST#2022-12-27~2023-01-17': '300'} for key, value in x ...

Python - error: exceeding index range

I am currently working on an example text from Python. Afghanistan:32738376 Akrotiri:15700 Albania:3619778 Algeria:33769669 American Samoa:57496 Andorra:72413 Angola:12531357 Anguilla:14108 Antigua and Barbuda:69842 Argentina:40677348 ...

Leveraging Selenium in Python for extracting values contained within react-text elements代码

click here for image descriptionI'm currently using Python's Selenium library to extract data from the web for my projects. I am facing a challenge in extracting the telephone number (e.g., 04 81 68 30 45) from this specific HTML source code: &a ...

Developing a cylinder in PyOpenGL without relying on the gluCylinder function

In my attempt to use pyopengl to create a cylinder, I encountered an issue where the top of the cylinder is not circular while the bottom is. The problem is illustrated in the image linked below. I am unsure if the issue lies in my code or if it's sim ...

Encountered a problem during the installation of Selenium using pip3

I'm encountering issues while trying to install selenium. After running pip3 install -U selenium, I received the following error message: Exception: Traceback (most recent call last): File "/usr/local/lib/python3.5/site-packages/pip/basecomman ...

Celery Error: Unable to Receive Emails via Celery

New to Python Django and Celery, I'm looking to set up Celery locally. Right now, my focus is on configuring error emails for failed tasks. Here's what I've done so far: Added the following code to setting.py CELERY_SEND_TASK_ERROR_EMAILS ...

Having trouble utilizing the "page down" function efficiently in my web scraper

I have created a small Python script using Selenium to automatically scroll down a webpage. However, my script only scrolls to a certain point because I am unsure of how to set the range parameter to reach the bottom. I currently have it set at 10 just as ...