When executing jobs in Jenkins pipeline and a job is failed at night how do you resume it in the same night?

When executing selenium jobs in Jenkins pipeline and a job is failed at night how do you resume it in the same night?

Solution:

You can use Naginator plugin to achieve your intended behavior. Configure it as follows:

Install the plugin -> check the Post-Build action “Retry build
after failure” on your project’s configuration page.

If the build fails, it will be rescheduled to run again after the time you specified. You can choose how many times to retry running the job. For each consecutive unsuccessful build, you can choose to extend the waiting period.

How to maximize window in Jenkins using Python, Selenium Webdriver and Chromedriver?

How to maximize a window in Jenkins?
I tried to maximize window using:

chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_argument("--start-maximized")
self.driver = webdriver.Chrome(chrome_options=chromeOptions)


driver.maximize_window()

driver.set_window_size(1920,1080)

driver.fullscreen_window()

All works when I run the test in PyCharm, but in Jenkins, the window does not change size.

Solution:

The problem is with Jenkins running as a windows service.

In Windows command prompt, go to folder where jenkins-cli.jar file is located.

And stop the service.

java -jar jenkins-cli.jar -s http://localhost:8080 safe-shutdown --username "YourUsername" 
--password "YourPassword"

Have Jenkins run from the command prompt using a script.

Python + Selenium WebDriver, click on submit button

I am working on a web scraper where I need to click the submit button to trigger a JavaScript script to load a page. I am not able to identify the right tag and perform the click() function. I am thinking this has to do something with the aria-hidden="true" tag. Can you please let me know how we can achieve this?

Here is the page_source section for the button:

Search  

Here is the code that I have:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

driver = webdriver.PhantomJS(executable_path='C:/Users/50178/Documents/learn/pracpy/phantomjs-2.1.1-windows/phantomjs-2.1.1-windows/bin/phantomjs.exe')
#driver = webdriver.Chrome(executable_path='C:/Users/50178/Documents/learn/pracpy/ChromeDriver/chromedriver.exe')
driver.get("http://www16.co.hennepin.mn.us/cfrs/search.do")
driver.implicitly_wait(5)
driver.find_element_by_css_selector("input[type='radio']").click()
print(driver.page_source)
print (driver.find_element_by_xpath('.//div[@class="btn btn-primary"]'))
driver.close()

Solution:

"btn btn-primary" is a class name of button, but not div. Try

//button[@class="btn btn-primary"]

or

//button[.="Search"]

Trouble getting few items from a webpage

I’ve written a script in python in combination with selenium to parse some items from a webpage. I can’t get it working in anyway. The items I’m after are (perhaps) within iframe. I tried to switch it but that doesn’t have any effect. I’m still getting nothing except for TimeoutException when it hits the line where I tried to switch the iframe. How can i get it working. Thanks in advance:

Here goes the webpage link: URL

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

url = "replace_with_above_url"

driver = webdriver.Chrome()
driver.get(url)
wait = WebDriverWait(driver, 10)

wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "tradingview_fe623")))

for item in wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, ".quick .apply-common-tooltip"))):
    print(item.text)

driver.quit()

Elements within which the items I’m after:

5 1h 1D 1M 1D

This is the output I’m expecting to have (it works locally when i try to get them using css selectors):

5
1h
1D
1M
1D

This is how it looks in the web:

enter image description here

Solution:

Required nodes located inside 2 nested iframes, so you need to switch to them one by one. Note that id/name of second one generated dynamically. Just try to replace

wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "tradingview_fe623")))

with

wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, ".abs")))
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[id^='tradingview_']")))