Creating a GUI for Selenium - python

I want to create a GUI for this code that automatically downloads PDF's. But I am not sure where to start. These are 2 inputs I need to change.
drp.select_by_visible_text('**Dan Pitts**')
checkfield=wait.until(EC.element_to_be_clickable((By.XPATH,'//*[#id="FieldCheckBox-**701847**"]')))
So just 2 input boxes and then have a submit button for it to open chrome and start.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
import time
driver=webdriver.Chrome()
driver.get('')
username=driver.find_element_by_xpath('//*[#id="username"]')
username.send_keys('')
password=driver.find_element_by_xpath('//*[#id="password"]')
password.send_keys('')
login=driver.find_element_by_xpath('/html/body/pcs-root/pcs-site-wrapper/div/div/div/div/pcs- login/div/form/button')
login.click()
time.sleep(10)
driver.switch_to.frame('pcsIFrame')
growerlist=driver.find_element_by_xpath('//*[#id="GrowerDropDownList"]')
drp=Select(growerlist)
drp.select_by_visible_text('**Dan Pitts**')
wait=WebDriverWait(driver,30)
getfields=driver.find_element_by_xpath('//*[#id="GetFieldsButton"]')
getfields.click()
##time.sleep(4)
checkfield=wait.until(EC.element_to_be_clickable((By.XPATH,'//*[#id="FieldCheckBox-**701847**"]')))
checkfield.click()

I have put the two input boxes in and it does work for the Grower. I cant seem to get it to work with xpath though.

Related

Cant click or send keys, selenium webdriver python

I am trying to access the following website:
and apply some filters like click on and select a date. When I click on I want to select one of the two options. But I cant click with xpath neither can I send keys to to type in what I want. Can someone help me by finding how I can click on and right after that select one of the two options and click the green button so that I can click afterwards on the date?
here is what I got so far in code (Python)
%pip install selenium webdriver_manager
import requests
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support.ui import WebDriverWait
driver = webdriver.Chrome()
driver.get(url_dist_vacinas)
print(driver.title)
driver.find_element(By.XPATH,'//*[#id="filtro-04"]/div/article/div[1]/div/div/qv-
filterpane/div/div/div/div[2]/span').click()
Try the below lines of code, this might help
driver.get("https://infoms.saude.gov.br/extensions/DEMAS_C19VAC_Distr/DEMAS_C19VAC_Distr.html")
clickReviw = WebDriverWait(driver, 40).until(EC.element_to_be_clickable((By.XPATH, "//*[text()='Tipo de vacina']")))
clickReviw.click()
sleep(4)
driver.find_element_by_xpath("//input[#placeholder='Search in listbox']").send_keys("vacina")
btn1 = driver.find_element_by_xpath("(//div[#class='qv-listbox-text qv-listbox-text-value'])[1]")
btn1.click()
btn2 = driver.find_element_by_xpath("//button[#title='Confirm selection']")
btn2.click()
Imports
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep

Switch to another popup window in selenium - python

I want to Switch to another window to close it however i am unable to do it. I have added explicit wait so that the close button can appear and then i can close it
I thought it must be iframe but it is not need a help on this
Below is the screen shot and code for it
The main code which i have implemented is on the last line
enter image description here
Below is code
from selenium.webdriver.chrome.webdriver import WebDriver
from utilities.BaseClass import BaseClass
import pytest
from selenium import webdriver
from selenium.webdriver import ActionChains
import time
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.common.by import By
driver = webdriver.Chrome(executable_path="C:\chromedriver")
driver.get("https://www.seleniumeasy.com/test/")
driver.maximize_window()
time.sleep(5)
driver.find_element_by_xpath("//a[text()='No, thanks!']").click()
driver.find_element_by_link_text("Progress Bars & Sliders").click
driver.execute_script("window.scrollTo(300, 500)")
driver.find_element_by_link_text("Progress Bars & Sliders").click()
driver.find_element_by_link_text("JQuery Download Progress bars").click()
driver.find_element_by_xpath("//button[#id='downloadButton']").click()
wait = WebDriverWait(driver,20)
wait.until(ec.element_to_be_clickable((By.XPATH,"//button[#type='Close']")))
driver.find_element_by_xpath("//button[#type='Close']").click()
You are using a wrong locator //button[#type='Close'] here:
wait.until(ec.element_to_be_clickable((By.XPATH,"//button[#type='Close']")))
driver.find_element_by_xpath("//button[#type='Close']").click()
It should be //button[text()='Close'].
So instead of the above try this:
wait.until(ec.element_to_be_clickable((By.XPATH,"//button[text()='Close']"))).click()
The entire code will be:
from selenium.webdriver.chrome.webdriver import WebDriver
from utilities.BaseClass import BaseClass
import pytest
from selenium import webdriver
from selenium.webdriver import ActionChains
import time
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.common.by import By
driver = webdriver.Chrome(executable_path="C:\chromedriver")
driver.get("https://www.seleniumeasy.com/test/")
driver.maximize_window()
time.sleep(5)
driver.find_element_by_xpath("//a[text()='No, thanks!']").click()
driver.find_element_by_link_text("Progress Bars & Sliders").click
driver.execute_script("window.scrollTo(300, 500)")
driver.find_element_by_link_text("Progress Bars & Sliders").click()
driver.find_element_by_link_text("JQuery Download Progress bars").click()
driver.find_element_by_xpath("//button[#id='downloadButton']").click()
wait = WebDriverWait(driver,20)
wait.until(ec.element_to_be_clickable((By.XPATH,"//button[text()='Close']"))).click()

Cannot select more dropdowns with Selenium Python

I am trying to scrape for car prices from this website:
To get car prices, you should fill out the form and I have to choose from dropdowns using Selenium.
I am using this code to choose from dropdowns:
# Imports
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
year_dropdown = Select(WebDriverWait(driver, 5)
.until(EC.element_to_be_clickable((By.ID, "j_id_3q-carInfoForm-year-selectOneMenu"))))
year_dropdown.select_by_value('2015')
But after I chose the year, it just keeps loading and never stops:
Any suggestions please?
I resolved the issue by using a real chrome driver. I was using chromdriver-manager package and when I removed it and downloaded a real chrome driver, the issue was gone.

Selenium: Why isn't a button click carried out?

I would like to click the "Search" button on a website. Then the next page opens. The click is not carried out (not even with built-in time.sleeps(3)), but an error message is not thrown.
What am I doing wrong?
import time
import sys
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
driver = webdriver.Chrome('G:\\chromedriver\\chromedriver.exe')
driver.get("https://www.immobilienscout24.de")
driver.execute_script("return document.readyState") == "complete"
element = driver.find_element_by_id("oss-location")
#element.clear()
element.send_keys("10115 Berlin")
btn=WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//button[#class='oss-main-criterion oss-button button-primary one-whole']")))
#btn.click()#trial 1
#driver.execute_script("arguments[0].click();", btn) #trial 2
print("ready")
I would suggest after inserted the value in search box wait for auto search result and then click the auto search result.Then click on the treffer button.
Code:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
driver = webdriver.Chrome('G:\\chromedriver\\chromedriver.exe')
driver.get("https://www.immobilienscout24.de")
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.ID,"oss-location"))).send_keys("10115 Berlin")
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"(//li[#class='ui-menu-item'][contains(.,'10115 Berlin')])[1]"))).click()
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//button[#class='oss-main-criterion oss-button button-primary one-whole']//span[contains(.,'Treffer')]"))).click()

Not Able to See Entire Page Source of Website using Selenium,Python

I am trying to scrape this website
https://script.google.com/a/macros/cprindia.org/s/AKfycbzgfCVNciFRpcpo8P7joP1wTeymj9haAQnNEkNJJ2fQ4FBXEco/exec
I am using selenium and python.I am not able to view entire page source,Basically i have to scrape the table inside it and click on next button,but the code of next and table not visible on page source.Here is my code
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from bs4 import BeautifulSoup
from selenium import webdriver
browser = webdriver.PhantomJS()
browser.get(link)
pass1 = browser.find_element_by_xpath("/html/body/div[2]/table[2]/tbody/tr[1]/td/div/div/div[2]/div[2]")
pass1.click()
time.sleep(30)
I am getting this error,NoSuchElementException.
There are two iframes present on the page, so you need to first switch on those iframe and then you need to click on the element.
And you can apply explicit wait on the element so that the script waits until the element is visible on the page.
You can do it like:
browser = webdriver.PhantomJS()
browser.get(link)
browser.switch_to.frame(driver.find_element_by_id('sandboxFrame'))
browser.switch_to.frame(driver.find_element_by_id('userHtmlFrame'))
WebDriverWait(browser, 20).until(EC.presence_of_element_located((By.XPATH, "//div[contains(#class,'charts-custom-button-collapse-left')]//div"))).click()
Note: You have to add the following imports:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

Categories