I'm trying to input an id into this website, however, anything I search for inside of the table shows up as "unable to locate element".
id_field = driver.find_element_by_xpath('//*[#id="p01aForm_b_studentId"]')
doesn't seem to provide the element.
driver = webdriver.Chrome()
driver.get("https://www.e-license.jp/el25/?abc=lEPHbvBGJVY%2BbrGQYS%2B1OA%3D%3D")
login_link = driver.find_element_by_xpath('//a[#href="'+"https://www.e-license.jp/el25/?abc=lEPHbvBGJVY%2BbrGQYS%2B1OA%3D%3D"+'"]')
login_link.click()
driver.find_element_by_id("p01aForm_b_studentId")
If you want to click that link try this. I'm not sure why your trying to open up the tab if you want the first site's id.
wait = WebDriverWait(driver, 10)
driver.get("https://www.e-license.jp/el25/?abc=lEPHbvBGJVY%2BbrGQYS%2B1OA%3D%3D")
wait.until(EC.element_to_be_clickable((By.ID, "p01aForm_b_studentId"))).send_keys("a")
#wait.until(EC.element_to_be_clickable((By.XPATH, "//a[contains(#href,'https://www.e-license')]"))).click()
Imports
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Related
I'm trying to click this button shown after choosing an option from a drop-down menu.
This is the button I'm trying to click.
The link to the website: https://excise.wb.gov.in/CHMS/Public/Page/CHMS_Public_Hospital_Bed_Availability.aspx
The html:
I've tried using XPATH, and through visible text; nothing seems to work.
My code as of now:
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.ui import Select
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://excise.wb.gov.in/CHMS/Public/Page/CHMS_Public_Hospital_Bed_Availability.aspx")
drop_dist = \
driver.find_element(By.XPATH, "/html/body/form/div[3]/main/div[2]/div/div[2]/div/div[1]/div[2]/div/select")
select_dist = Select(drop_dist)
select_dist.select_by_value("005")
l = driver.find_element(By.XPATH, "/html/body/form/div[3]/main/div[2]/div/div[2]/div/div[4]/div/div/table/tbody/tr[1]/td/div/div[2]/div[2]/div[1]/a").click()
time.sleep(30)
Any help is much appreciated!
The locator seems fragile, use following locator and webdriverwait() to handle sync issue.
driver.get("https://excise.wb.gov.in/CHMS/Public/Page/CHMS_Public_Hospital_Bed_Availability.aspx")
wait=WebDriverWait(driver, 20)
select_dist =Select(wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#ctl00_ContentPlaceHolder1_ddl_District"))))
select_dist.select_by_value("005")
wait.until(EC.element_to_be_clickable((By.XPATH, "(//a[#class='btn btn-link' and contains(., 'View Detail Break up')])[1]"))).click() //this will click the first one only.
You have to add 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
Try this:
button = driver.find_elements(By.CSS, 'a[role="button"][aria-expanded="false"]')[0]
button.click()
You can change the index in order to click on other elements
I'm trying to login to a webpage using Selenium but when I enter the relevant email address and try to click continue I get the no such element exception.
driver = webdriver.Safari()
driver.get('https://manage.statuspage.io/login')
email = driver.find_element_by_id('email')
email.clear()
email.send_keys('XXX')
driver.find_element_by_id("login-btn").click()
driver.find_element_by_id("login-submit").click()
The error occurs on the last line.
As you can see I'm searching for this continue button via id 'login-submit' but it says that it doesn't exist.
Any help would be great!
After clicking
driver.find_element_by_id("login-btn").click()
It takes you to another page where the login-submit element is presented.
But you trying to click this element immediately after clicking on element on previous page while the new page is still not loaded.
You should add a wait to wait for that element on the second page to appear before accessing it.
This should work:
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
driver = webdriver.Safari()
wait = WebDriverWait(driver, 20)
driver.get('https://manage.statuspage.io/login')
email = wait.until(EC.visibility_of_element_located((By.ID, "email")))
email.clear()
email.send_keys('XXX')
wait.until(EC.visibility_of_element_located((By.ID, "login-btn"))).click()
wait.until(EC.visibility_of_element_located((By.ID, "login-submit"))).click()
You need to wait for the element/locator to appear on the webpage.
from selenium.webdriver.support import expected_conditions as EC
driver.find_element_by_id("login-btn").click()
login_button = WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located((By.ID, 'login-submit')))
login_button.click()
You can use explicitWait like below to click on the desired button
driver.find_element_by_id("email").send_keys("email")
OR
email = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.ID, "email")))
email.send_keys('email')
btnLogin = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.ID,"login-btn")))
btnLogin.click()
import
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
What happened sometime when you send request from a script it returns you page with different ids or class names. After driver.get('https://manage.statuspage.io/login') line save the webpage as .html file and see the id or class name there.
the link I'm trying to scrape is https://hcad.org/property-search/real-property/real-property-search-by-account-number/
I'm using this method currently
driver.get('https://hcad.org/property-search/real-property/real-property-search-by-account-number/')
driver.implicitly_wait(2)
driver.find_element_by_xpath('/html/body/div[1]/div[3]/div/h1').click()
actions.send_keys(Keys.TAB * 2 )
actions.send_keys(account_num)
actions.send_keys(Keys.TAB)
actions.send_keys(Keys.RETURN)
actions.perform()
to type the account number in search box and search it which gives me a new form.
I tried to find the input area using full xpath but it never works.
Is there is anyway I can write account num using element xpath or I can excess the form elements other then actions method.
I tried different methods.
like searching input area using (id,full xpath) using driver implicity wait function but none of them work please help me here so that I can grab elements using your method on the form I get after typing account number I'm lost.
You are using wrong locator.
Also, I don't understand why are you using Actions instead of Selenium.send_keys()?
I would do this as following:
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.webdriver.common.keys import Keys
wait = WebDriverWait(driver, 20)
driver.get('https://hcad.org/property-search/real-property/real-property-search-by-account-number/')
wait.until(EC.frame_to_be_available_and_switch_to_it(driver.find_element_by_xpath("//iframe")))
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'input[name="searchval"]'))).send_keys(account_num)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'input[type="submit"]'))).click()
The search field is in iframe, you would need to switch the driver focus :
code :
driver.maximize_window()
wait = WebDriverWait(driver, 10)
driver.get('https://hcad.org/property-search/real-property/real-property-search-by-account-number/')
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[src='https://public.hcad.org/records/Real.asp']")))
driver.find_element_by_id('acct').send_keys("12345")
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input[value='Search']"))).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
Using selenium automation webdriver i'm unable to locate the text box element on a travel website using python. Using locator present in the webdriver such as Id/name/css_selector/class_name or xpath/full xpath.
Below is the screenshot of the python code:
[Code_1][1]
While the first one is located the second one isn't. The corresponding HTML code is
[text_box2][2]
How can i fill(automate) both fileds corresponding flight destinations i.e leaving and going
[1]: https://i.stack.imgur.com/gpoIr.jpg
[2]: https://i.stack.imgur.com/Q7mGs.jpg
Here is a slightly different approach for locating things. I am using waits borrowed from CruisePandey in this thread. I used firefox, but that is adaptable. Some notes of what was hard:
I had to make sure to be on the Flights tab.
I had to click in the from and to fields, which were buttons after all, and then wait to be able to type into the revealed input fields.
Finally, I had to choose the first element from the dropdown list that resulted.
from selenium import webdriver
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.Firefox(executable_path='/usr/bin/geckodriver')
driver.maximize_window()
driver.get('https://www.expedia.co.in')
wait = WebDriverWait(driver, 15)
wait.until(EC.presence_of_element_located((By.LINK_TEXT, "Flights")))
driver.find_element_by_link_text('Flights').click()
wait.until(EC.presence_of_element_located((By.ID, "location-field-leg1-origin")))
driver.find_element(By.CLASS_NAME,'uitk-faux-input').click()
fieldInput = driver.find_element_by_id('location-field-leg1-origin')
wait.until(EC.visibility_of(fieldInput))
fieldInput.send_keys("SFO")
wait.until(EC.presence_of_element_located((By.TAG_NAME, "strong")))
driver.find_element_by_tag_name('strong').click()
driver.find_elements(By.CLASS_NAME,'uitk-faux-input')[1].click()
fieldInput = driver.find_element_by_id('location-field-leg1-destination')
wait.until(EC.visibility_of(fieldInput))
fieldInput.send_keys("BOS")
wait.until(EC.presence_of_element_located((By.XPATH,"//strong[contains(text(), 'Boston')]")))
driver.find_element_by_xpath("//strong[contains(text(), 'Boston')]").click()
You may want to use the below xpath for going To input field :
//label[text()='Going to']//following-sibling::input[#name]
Code :
wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.XPATH, "//label[text()='Going to']//following-sibling::input[#name]"))).send_keys('something')
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 automate from 1 place holder to another, i have use this set of code & it works for me
wait.until(EC.element_to_be_clickable((By.XPATH,"//*[#id='location-field-leg1-origin-menu']/div[2]/ul/li[1]/button"))).click()
b = wait.until(EC.element_to_be_clickable((By.XPATH, ".//*[#id='location-field-leg1-destination-menu']/div[1]/button"))).send_keys("NYC")
b = wait.until(EC.element_to_be_clickable((By.XPATH,".//*[#id='location-field-leg1-destination-menu']/div[2]/ul/li[1]/button"))).click()
c = wait.until(EC.element_to_be_clickable((By.XPATH, ".//*[#id='d1-btn']"))).click()
I have a sample code here which keeps saying that it cant find the element im looking for. Please help me, I want to find the element by the name and not the absolute Xpath
from selenium import webdriver
from time import sleep
browser = webdriver.Chrome()
browser.get('https://www.instagram.com')
sleep(5)
x = browser.find_element_by_xpath("//span[text() = 'Sign Up']").click()
When you get the instagram page you need to induce waits for the page to load and then click the parent a tag of that span.
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Sign up']/parent::a"))).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