I am trying to enter a field with text (email), in the username box. However, it is not interacting with it. I have it in a try & except statement but it only spits out excepts.
Website is account.protonmail.com/signup
I have tried everything: xpath, class, id, but nothing works. I am losing my mind!
Password works fine:
Does not work:
driver.find_element_by_xpath('//*[#id="username"]').send_keys(password)
Does work:
driver.find_element_by_xpath('//*[#id="repeat-password"]').send_keys(password)
And yes, I do wait until JavaScript finishes running.
it is in iframe, and needs explicit waits :-
driver = webdriver.Chrome(driver_path)
driver.maximize_window()
driver.get("https://account.protonmail.com/signup")
wait = WebDriverWait(driver, 20)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[sandbox^='allow-scripts']")))
ele = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#username"))).send_keys('someemail#gmail.com')
Imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Element you are trying to access is inside an iframe. First you need to switch to the frame like this
driver.switch_to.frame(driver.find_element_by_xpath("//iframe[contains(#src,'account-api.protonmail.com')]"))
It's very difficult for you to write everything, make it easier
click = driver.find_element_by_xpath('//*[#id="username"]').click()
click.send_keys('')
click.send_keys(password)
Related
Im trying to create automation for a cookie clicker website.
I need to click on elements (like the cursor element for example) on the website when they go from "blocked" to "unlocked" I have been trying for 2 days now and I have tried using the WebDriverWait but nothing is working no matter what my code does not detect when the element becomes available.
this is my code right now
import time
import ec as ec
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
Play = True
ser_obj = Service("\Progr\OneDrive\Documents\PythonFolder\chromedriver.exe")
driver = webdriver.Chrome(service=ser_obj)
driver.get(url="https://orteil.dashnet.org/cookieclicker/")
WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.cc_btn.cc_btn_accept_all"))).click()
WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.langSelectButton.title#langSelect-EN"))).click()
time.sleep(1)
Cookie = driver.find_element(By.CSS_SELECTOR, "#cookieAnchor #bigCookie")
while Play:
Cookie.click()
Cookie_number = (driver.find_element(By.XPATH,'//*[#id="cookies"]').text)
print(Cookie_number)
WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, '//*[#id="product0"]'))).click()
and for whatever reason I cannot click on the cookie unless I have a time.sleep() method called and I do not know why. I have tried using WebDriverWait to wait when the cookie becomes avaible to click, but nope, it wont run without the time.sleep().
Any help would be great.
I have tried using if statments with the .isDisplayed() function.
I have tried using "try-except" methods.
I have tried giving Play a value and then saying when that value reaches 0, check to see if the cursor is available to click.
I have tried using CSS Selectors and Xpath
I have a hard time locating two input elements of a specific website.
Well, as you can see above, "username" input element and "password" input element are inside an iframe with id = tab1.
So I tried (among other things) something like this:
driver = webdriver.Firefox()
driver.get('https://www.website.com/sites/en/Pages/default.aspx')
driver.SwitchTo().Frame(driver.FindElement(By.id("tab1")));
username = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '//*[#id="login-form"]/div[1]/input')))
username.send_keys(credentials.username)
password = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '//*[#id="login-form"]/div[2]/input')))
password.send_keys(credentials.password)
submit = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[#id="loginBtn"]')))
action = ActionChains(driver)
action.move_to_element(submit).click().perform()
That is, I switched to frame "tab1" and then searched for the elements with their XPath. (Both full XPath and simple XPath).
But I get the following error again and again:
Process finished with exit code -1073740791 (0xC0000409)
without even activating "try-except" to show me something I can use for debugging.
Well, the question is: can I locate these elements somehow?
Thank you in advance.
wait=WebDriverWait(driver,10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"#tab1")))
You are using Java use Python instead and waits.
driver.SwitchTo().Frame(driver.FindElement(By.id("tab1")));
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 search www.oddschecker.com using Python and Selenium (chromedriver) but am struggling to populate the search field with the search term.
The code below clicks the magnifying glass ok but the send_keys statement does not populate the expanded search box.
Can anyone see the issue?
driver.find_element_by_xpath('//*[#id="top-menu"]/li[8]/ul/li[1]/span/span').click()
sleep(5)
driver.find_element_by_xpath('/html/body/div[1]/header/div[1]/div/div[1]/div/ul/li[8]/ul/li[1]/div/div/div/form/fieldset/input').send_keys('Bicep')
xpath is brittle, please use relative xpath. see below.
Use explicit waits.
Close modal pop up may appear sometime, may not appear sometime so better to wrap them inside try and except block.
Code :
driver = webdriver.Chrome(driver_path)
driver.maximize_window()
#driver.implicitly_wait(30)
wait = WebDriverWait(driver, 30)
driver.get("http://www.oddschecker.com/")
try:
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.js-close-class"))).click()
print('Clicked on close button if it appears')
except:
pass
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[starts-with(#data-ng-click,'NavSearchCtrl')]"))).click()
search = wait.until(EC.visibility_of_element_located((By.ID, "search-input")))
search.send_keys('Bicep', Keys.RETURN)
Imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
I'm attempting to automate some work with selenium and I'm having issues sending keys to the input id when attempting to login and I'm wondering if I'm in over my head.
I've tried locating the element by xpath, id as well as class, with no luck. I've also tried to wait to make sure the element is visible with no luck. Perhaps it's due to the div xmlnsis inside a body xmlns, resulting in the elements within the div xmlns initially not being visible? If so, how do I go about making the input box visible?
This is basically how far I've come:
from selenium import webdriver
from selenium.webdriver.support.ui import Select
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.common.by import By
# website url
url = "https://tx-production-eu-web.production.eu1.tx.klarna.net/radix/"
# driver
driver = webdriver.Chrome(r"C:\Users\ahmed.khairouni\Desktop\driver\chromedriver.exe")
driver.get(url)
# wait for page to load
wait = WebDriverWait(driver, 5)
#locate element and insert text into textbox
username = wait.until(EC.presence_of_element_located((By.ID, "wf_139389")))
search_input.send_keys('username')
Linked you can find part of the web code: https://imgur.com/WVKo7B7
Appreciate any help and thank you in advance.
The issue here might be the input is using a dynamic ID, so finding by ID may not work. I also noticed you are locating username, but then you are sending keys to search_input, which does not seem to exist in your code. That may be causing your issue, unless you made a typo in this question.
You could try using an XPath to locate the username input:
username = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//input[contains(#class, 'rwt-regular-value')]")))
username.send_keys('username')
I've written a script using python with selenium to click on some links listed in the sidebar of google maps. When any of the items get clicked, the related information attached to each lead shows up in the right sided area. The script is doing fine. However, I've used hardcoded delay to do the job. How can I get rid of hardcoded delay by achieving the same with explicit wait. Thanks in advance.
Link to the site: website
The script I'm trying with:
import time
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
link = "replace_with_above_link"
driver = webdriver.Chrome()
driver.get(link)
wait = WebDriverWait(driver, 10)
for item in wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "[id^='rlimg0_']"))):
item.location
time.sleep(3) #wish to try with explicit wait but can't find any idea
item.click()
driver.quit()
I tried with wait.until(EC.staleness_of(item)) instead of hardcoded delay but no luck.
If you want to wait until new data displayed after each clcik you may try below:
for item in wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "[id^='rlimg0_']"))):
div = driver.find_element_by_xpath("//div[#class='xpdopen']")
item.location
item.click()
wait.until(EC.staleness_of(div))