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
Related
So I'm trying to scrape some information from a website and can't get through a pop-up window. I've tried using short and full Xpath of the X button but it doesn't close.
here is my code
# import
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome(executable_path = 'mypath/chromedriver.exe')
driver.get('https://ai.fmcsa.dot.gov/SMS')
driver.find_Element_By_xpath('//*[#id="simplemodal-container"]/a').click();
The code does open the website but doesn't close the pop-up. What might be the issue?
You automation script needs an explicit waits, and the below xpath :-
//a[#title='Close']
Code : -
driver = webdriver.Chrome(executable_path = 'mypath/chromedriver.exe')
driver.maximize_window()
#driver.implicitly_wait(50)
driver.get("https://ai.fmcsa.dot.gov/SMS")
wait = WebDriverWait(driver, 20)
wait.until(EC.element_to_be_clickable((By.XPATH, "//a[#title='Close']"))).click()
Imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
If you want to use your code as is:
# import
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome(executable_path = 'mypath/chromedriver.exe')
driver.get('https://ai.fmcsa.dot.gov/SMS')
driver.find_Element_By_xpath('/html[1]/body[1]/div[7]/a[1]').click();
This worked for me and closed the pop up window.
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()
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.
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()
I want to go to this site: https://www.pluginillinois.org/offers.aspx?said=2
Each time I have some code that looks like the following:
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
import time
import pyautogui
driverpath = r"C:\Users\chromedriver.exe"
browserProfile = webdriver.ChromeOptions()
browserProfile.add_experimental_option('prefs', {'intl.accept_languages': 'en,en_US'})
browser = webdriver.Chrome(driverpath, options=browserProfile)
browser.get('https://www.pluginillinois.org/offers.aspx?said=2')
My Selenium browser will open and go to a completely different URL instead. The browser will instead go to https://www.pluginillinois.org/OffersBegin.aspx.
Is there a way to obfuscate this behavior?