I am writing code to automate the searching of a hotel room, with specific check-in and check-out dates, and the number of people. I'm doing this on Trivago, but am having trouble interacting with the datepicker element on the site.
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import ElementNotVisibleException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
trivagourl = 'https://www.trivago.co.uk/'
browser = webdriver.Chrome(r"C:\\Users\\conor\\Desktop\\diss\\chromedriver.exe")
browser.get(trivagourl)
time.sleep(2)
trivagosearch = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[#id="querytext"]')))
trivagosearch.send_keys('mayflower london')
trivagosearch.send_keys(Keys.ENTER)
This code works for entering a destination name and hitting enter, which takes the user to the datepicker element, but because it's not a data input field in HTML I'm not sure how to automate it.
Related
someone of you, can close the first modal on the website of flight company easyjet, accepting the cookie policy?
i tryed in many way but never closed it
this is my code
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import time
import os
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.easyjet.com/it")
time.sleep(2)
#chiudi cookie
cookie = driver.find_element(By.id,"ensCloseBanner")
cookie.click()
time.sleep(2)
I believe it's a typo. instead of id it should be ID
cookie = driver.find_element(By.ID,"ensCloseBanner")
Reference link : Selenium python locator
I am new to python and selenium. Trying to automate download of files from the dropdown menu on the below link for the first time. The code gets stuck after page loads i.e the drop down does not work and gives me an error. Sorry if my code looks clunky. Any help is appreciated.
Thanks
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
import time
s=Service("C:\\python\\chromedriver.exe")
driver = webdriver.Chrome(service=s)
driver.maximize_window()
driver.get('http://www.amfiindia.com/research-information/aum-data/classified-average-aum')
#monthname=driver.find_element(By.XPATH,"//*[#id='AaumDate']")
monthdd=Select(monthname)
monthdd.select_by_value('01-Jan-22')
time.sleep(3)
typename=driver.find_element(By.XPATH,"//*[#id='AumType']")
typedd=Select(typename)
typedd.select_by_visible_text('Scheme category wise')
time.sleep(3)
mfname=driver.find_element(By.XPATH,"//*[#id='AumMFName']")
mfdd=Select(mfname)
mfdd.select_by_visible_text('All')
time.sleep(3)
driver.find_element("class name","sprite-inter go-btn").click()
wait=WebDriverWait(driver,20)
driver.get('http://www.amfiindia.com/research-information/aum-data/classified-average-aum')
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#divAumPeriod > span > a > span.ui-button-text"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH,"//*[#class='ui-menu-item']/a[.='January - 2022']"))).click()
Most of these tags open like so and have another list with them that's not using the select tag.
Imports:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
I am trying to get some data from this website link
This is my code:
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
import time
driver = webdriver.Edge("C:/Users/Hamita/Documents/msedgedriver.exe")
driver.get("https://www.bountou1x2.com/sport.jsp?ispt=null")
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//*[#id=\"iframe-alto-sinistra\"]")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH,"//*[#id=\"left-menu-container\"]/div[1]/div[1]"))).click()
But it's giving me this error:
selenium.common.exceptions.TimeoutException
The button i want to click is to select Today, it's located in the left side
Help is appreciated, thanks to all of you
The <iframe> you are trying to switch to is located by the following ID receiver
So you should use:
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"receiver")))
instead of
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//*[#id=\"iframe-alto-sinistra\"]")))
I am using Selenium with Python on a webpage with JavaScript. The script runs until a pop=up asks for a click either to agree or seek More Options labels appear. The HTML for the pop-up disappears if an option is manually clicked. Would appreciate some guidance on how to click "Agree" automatically.
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
driver = webdriver.Chrome(executable_path='C:/A38/chromedriver_win32/chromedriver.exe')
driver.implicitly_wait(30)
driver.maximize_window()
# Navigate to the application home page
driver.get("https://www.sportinglife.com/racing/results/2020-11-23")
To click on the button with text AGREE. First induce waits for page load and then wait for the element to be clickable.
driver.get('https://www.sportinglife.com/racing/results/2020-11-23')
wait=WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='AGREE']"))).click()
Import
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
This will do the trick:
driver.find_element_by_xpath('//*[#id="qc-cmp2-ui"]/div[2]/div/button[2]').click()
I've written a script in python using selenium to scrape some text out of a webpage. The text I wanna scrape generates upon filling in an inputbox. My script can fill in in the right way and can populate the value. However, it can't parse the text. How can I do it?
This is what I've tried so far:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 10)
driver.get("http://dev.delshlearning.com.au/test.php")
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR,"#AM"))).send_keys("`(2(3^5-sqrt(3)))/2`",Keys.RETURN)
item = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR,"#MQ"))).text
print(item)
driver.quit()
The send_keys() parameter is already filled in within the script for your consideration.
It is storing the text values in the attribute value. This should work:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 10)
driver.get("http://dev.delshlearning.com.au/test.php")
# I changed your locater to ID since it's a little more clear
wait.until(EC.visibility_of_element_located((By.ID,"AM"))).send_keys("`(2(3^5-sqrt(3)))/2`",Keys.RETURN)
item = wait.until(EC.visibility_of_element_located((By.ID,"MQ"))).get_attribute('value')
print(item)
driver.quit()
I found it by going to the element's properties as shown highlighted here: