• Home
  • Hosting
  • Tech
  • Server
  • Security
Mex Linux
  • Home
  • Hosting
  • Tech
  • Server
  • Security
No Result
View All Result
mexlinux.com
  • Home
  • Hosting
  • Tech
  • Server
  • Security
No Result
View All Result
mexlinux.com
No Result
View All Result

How to Refresh Selenium Page – Linux Hint

admin by admin
August 10, 2020
Home Latest
Share on FacebookShare on Twitter
Refreshing webpages is a quite common motion. We refresh the webpage to see the up to date outcomes. The identical factor is true for browser testing, net automation, and net scraping with Selenium net driver.On this article, I’m going to indicate you the right way to refresh a web page with the Selenium Python library. So, let’s get began.

Stipulations:

To check out the instructions and examples of this text, it’s essential to have,

1) A Linux distribution (ideally Ubuntu) put in in your pc.
2) Python Three put in in your pc.
3) PIP Three put in in your pc.
4) Python virtualenv package deal put in in your pc.
5) Mozilla Firefox or Google Chrome net browsers put in in your pc.
6) Should know the right way to set up the Firefox Gecko Driver or Chrome Net Driver.

For fulfilling the necessities 4, 5, and 6, learn my article Introduction to Selenium with Python Three at Linuxhint.com.

Yow will discover many articles on the opposite matters on LinuxHint.com. Make sure you examine them out in the event you want any help.

Setting Up a Venture Listing:

To maintain every part organized, create a brand new mission listing selenium-refresh/ as follows:

$ mkdir -pv selenium-refresh/drivers

How to Refresh Selenium Page – Linux Hint

Navigate to the selenium-refresh/ mission listing as follows:

How to Refresh Selenium Page – Linux Hint

Create a Python digital atmosphere within the mission listing as follows:

How to Refresh Selenium Page – Linux Hint

Activate the digital atmosphere as follows:

$ supply .venv/bin/activate

How to Refresh Selenium Page – Linux Hint

Set up Selenium Python library utilizing PIP3 as follows:

How to Refresh Selenium Page – Linux Hint

Obtain and set up all of the required net driver within the drivers/ listing of the mission. I’ve defined the method of downloading and putting in net drivers in my article Introduction to Selenium with Python 3. In the event you want any help, search on LinuxHint.com for that article.

How to Refresh Selenium Page – Linux Hint

Methodology 1: Utilizing the refresh() Browser Methodology

The primary methodology is the best and the really helpful methodology of the refreshing web page with Selenium.

Create a brand new Python script ex01.py in and kind within the following traces of codes in it.

from selenium import webdriver
from selenium.webdriver.frequent.keys import Keys
from time import sleep
choices = webdriver.ChromeOptions()
choices.headless = True
browser = webdriver.Chrome(executable_path=”./drivers/chromedriver”, choices=choices)
browser.get(“https://www.unixtimestamp.com/”)
timestamp = browser.find_element_by_xpath(“//h3[@class=’text-danger’][1]”)
print(‘Present timestamp: %s’ % (timestamp.textual content.break up(‘ ‘)[0]))
sleep(5)
browser.refresh()
timestamp = browser.find_element_by_xpath(“//h3[@class=’text-danger’][1]”)
print(‘Present timestamp: %s’ % (timestamp.textual content.break up(‘ ‘)[0]))
browser.shut()

When you’re carried out, save the ex01.py Python script.

How to Refresh Selenium Page – Linux Hint

Line 1 and a pair of imports all of the required Selenium parts.

How to Refresh Selenium Page – Linux Hint

Line Three imports sleep() perform from time library. I’ll use this to attend a couple of seconds for the webpage to replace in order that we will fetch new information after refreshing the webpage.

How to Refresh Selenium Page – Linux Hint

Line 5 creates a Chrome Choices object, and line 6 allows headless mode for the Chrome net browser.

How to Refresh Selenium Page – Linux Hint

Line eight creates a Chrome browser object utilizing the chromedriver binary from the drivers/ listing of the mission.

How to Refresh Selenium Page – Linux Hint

Line 9 tells the browser to load the web site unixtimestamp.com.

How to Refresh Selenium Page – Linux Hint

Line 11 finds the ingredient that has the timestamp information from the web page utilizing the XPath selector and shops it within the timestamp variable.

Line 12 parses the timestamp information from the ingredient and prints it on the console.

How to Refresh Selenium Page – Linux Hint

Line 14 makes use of the sleep() perform to attend for five seconds.

Line 15 refreshes the present web page utilizing the browser.refresh() methodology.

How to Refresh Selenium Page – Linux Hint

Line 17 and 18 is identical as line 11 and 12. It finds the timestamp ingredient from the web page and prints the up to date timestamp on the console.

How to Refresh Selenium Page – Linux Hint

Line 20 closes the browser.

How to Refresh Selenium Page – Linux Hint

Run the Python script ex01.py as follows:

How to Refresh Selenium Page – Linux Hint

As you possibly can see, the timestamp is printed on the console.

How to Refresh Selenium Page – Linux Hint

After 5 seconds of printing the primary timestamp, the web page is refreshed, and the up to date timestamp is printed on the console, as you possibly can see within the screenshot under.

How to Refresh Selenium Page – Linux Hint

Methodology 2: Revisiting the Similar URL

The second methodology of refresh the web page is to revisit the identical URL utilizing the browser.get() methodology.

Create a Python script ex02.py in your mission listing and kind within the following traces of codes in it.

from selenium import webdriver
from selenium.webdriver.frequent.keys import Keys
from time import sleep
choices = webdriver.ChromeOptions()
choices.headless = True
browser = webdriver.Chrome(executable_path=”./drivers/chromedriver”, choices=choices)
browser.get(“https://www.unixtimestamp.com/”)
timestamp = browser.find_element_by_xpath(“//h3[@class=’text-danger’][1]”)
print(‘Present timestamp: %s’ % (timestamp.textual content.break up(‘ ‘)[0]))
sleep(5)
browser.get(browser.current_url)
timestamp = browser.find_element_by_xpath(“//h3[@class=’text-danger’][1]”)
print(‘Present timestamp: %s’ % (timestamp.textual content.break up(‘ ‘)[0]))
browser.shut()

When you’re carried out, save the ex02.py Python script.

How to Refresh Selenium Page – Linux Hint

Every thing is identical as in ex01.py. The one distinction is in line 15.

Right here, I’m utilizing the browser.get() methodology to go to the present web page URL. The present web page URL could be accessed utilizing the browser.current_url property.

How to Refresh Selenium Page – Linux Hint

Run the ex02.py Python script as follows:

How to Refresh Selenium Page – Linux Hint

As you possibly can see, the Pythion script ex02.py prints the identical kind of knowledge as in ex01.py.

How to Refresh Selenium Page – Linux Hint

Conclusion:

On this article, I’ve proven you 2 strategies of refreshing the present webpage utilizing the Selenium Python library. It’s best to have the ability to do extra fascinating issues with Selenium now.

selenium web driver refresh page,robot framework selenium refresh page,python reload selenium,python selenium refresh page source,how to reload a frame in selenium,selenium js reload page,selenium hard refresh,python selenium refresh page after click

admin

admin

Next Post
How to Refresh Selenium Page – Linux Hint

Workplace Security Policy: The Hour Need

Recommended.

How to Refresh Selenium Page – Linux Hint

Financial cybercrime 2019 Securelist

August 17, 2020
How to Refresh Selenium Page – Linux Hint

Election 2020-Keep misinformation from undercutting the vote

October 13, 2020

Trending.

How to Refresh Selenium Page – Linux Hint

Got Kids? Limit Computer Usage Per Account in Linux With Timekpr-nExt

October 29, 2020
How to Refresh Selenium Page – Linux Hint

How to restart the Ubuntu 20.04-Linux Hint network

September 25, 2020
How to Refresh Selenium Page – Linux Hint

LockBit ransomware seamlessly encrypts 225 systems

May 13, 2020
How to Refresh Selenium Page – Linux Hint

Download Ultimate ‘Security for Management’ Presentation Template

October 30, 2020
How to Refresh Selenium Page – Linux Hint

How to capitalize the first letter of the python string and other uses of the capitalize) (function – Linux Hint

May 5, 2020
mexlinux.com

MexLinux.com

We develop for Linux for a living, We used to develop for DOS.
Going from DOS to Linux is like trading a glider for an F117.

Categories

  • Hosting
  • Latest
  • Security
  • Server
  • Tech

Recent News

How to Refresh Selenium Page – Linux Hint

Delivering value to a remote workforce: A practical approach

November 19, 2020
How to Refresh Selenium Page – Linux Hint

Tetrade hackers target 112 financial apps with Ghimob banking TrojanSecurity Affairs

November 18, 2020
  • Home
  • Hosting
  • Tech
  • Server
  • Security

© 2020 MexLinux - Sitemap

No Result
View All Result
  • Home
  • Hosting
  • Tech
  • Server
  • Security

© 2020 MexLinux - Sitemap