How to connect to icloud.com with Selenium? - python

I'm trying to connect to https://icloud.com using selenium, but I keep timing out while trying to find the email input, which has id='account_name_text_field'
from selenium import webdriver
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.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
driver = webdriver.Firefox()
driver.get('https://icloud.com')
try:
email_input = WebDriverWait(driver, 10).until(EC.presence_of_element_located(
(By.ID, 'account_name_text_field')))
except TimeoutException:
print('timed out at email_input')
driver.close()
email_input.send_keys('johndoe#icloud.com')
email_input.send_keys(Keys.ENTER)
password_input = driver.find_element_by_id('password_text_field')
password_input.send_keys('password')
password_input.send_keys(Keys.ENTER)
What am I missing here?

The email and password inputs are in an iframe, so I needed to switch the driver context to the iframe:
from selenium import webdriver
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.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
def main(email, password):
driver = webdriver.Firefox()
driver.get('https://icloud.com/')
delay = 20
WebDriverWait(driver, delay).until(EC.frame_to_be_available_and_switch_to_it((By.ID, 'auth-frame')))
email_input = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.ID, 'account_name_text_field')))
email_input.send_keys(email)
email_input.send_keys(Keys.ENTER)
password_input = WebDriverWait(driver, delay).until(EC.element_to_be_clickable((By.ID, 'password_text_field')))
password_input.send_keys(password)
password_input.send_keys(Keys.ENTER)
Now that you can sign in, glhf trying to get past 2FA...

Related

TimeoutException error using wedrivier.wait in Selenium logging within glassdoor.co.in

I am going to scrap Glassdoor to extract companies' reviews! for the 1st step, I need to log in to extract all reviews, I put a time.sleep and wait time for clicking the "Singing" button, but I have still the following error:
raise TimeoutException(message, screen, stacktrace) TimeoutException
My code is like below:
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 TimeoutException, WebDriverException
from selenium.webdriver.chrome.options import Options
import time
import pandas as pd
from selenium.webdriver.common.action_chains import ActionChains
driver_path= r"C:\Users\TMaghsoudi\Desktop\chromedriver_win32.exe"
# chrome options
options = webdriver.ChromeOptions()
# options.add_argument("--start-maximized")
options.add_argument('--ignore-certificate-errors')
options.add_argument('--ignore-ssl-errors')
options.add_experimental_option('excludeSwitches', ['enable-logging'])
Pros =[]
Cons=[]
Re_Titles =[]
Re_rates= []
Employ_status= []
Re_dates = []
# set driver
driver = webdriver.Chrome(driver_path, chrome_options=options)
# get url
url = "https://www.glassdoor.co.in/Job/index.htm"
driver.get(url)
time.sleep(3)
driver.find_element(By.CLASS_NAME, "HeaderStyles__signInButton").click()
time.sleep(5)
Enter_email= driver.find_element(By.ID, "modalUserEmail")
Enter_email.send_keys("XXXXX")
Enter_email.send_keys(Keys.ENTER)
time.sleep(3)
Enter_pass= driver.find_element(By.ID,"modalUserPassword")
Enter_pass.send_keys("XXXX")
time.sleep(3)
# SingIn= WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[#class='d-flex align-items-center flex-column']/button[#class='gd-ui-button mt-std minWidthBtn css-1dqhu4c evpplnh0']")))
SingIn= WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "evpplnh1")))
SingIn.click()
To send a character sequence to the Email and Password field you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following locator strategies:
Using CSS_SELECTOR:
driver.get("https://www.glassdoor.co.in/Job/index.htm")
WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.d-lg-block button.HeaderStyles__signInButton"))).click()
WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#modalUserEmail"))).send_keys(email + Keys.RETURN)
WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#modalUserPassword"))).send_keys(password + Keys.RETURN)
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
Browser Snapshot:

Selenium NoSuchElementException: Message: no such element

I am struggling with Selenium
for the url: https://pubchem.ncbi.nlm.nih.gov/compound/2078
I am trying to click the button Download, but it doesn't find the element.
My 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
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.chrome.options import Options
from ipykernel import kernelapp as app
import time
options = webdriver.ChromeOptions()
driver_path = 'C:\\Users\\Idener\\Downloads\\chromedriver_win32\\chromedriver.exe'
driver = webdriver.Chrome(driver_path, options=options)
url = f"https://pubchem.ncbi.nlm.nih.gov/compound/2078"
driver.get(url)
driver.find_element_by_xpath("//*[#id='"'page-download-btn'"']").click()
enter image description here
Your XPath is not valid. You don't need so much quotes
driver.find_element_by_xpath("//*[#id='page-download-btn']").click()
You are missing a delay.
Element should clicked only when it is completely rendered and ready to accept a click event. WebDriverWait expected_conditions explicit waits should be used for that.
Also, no need to add f before URL value and '"' instead of ' in XPath expression.
The following code will work for you:
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
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.chrome.options import Options
from ipykernel import kernelapp as app
import time
options = webdriver.ChromeOptions()
driver_path = 'C:\\Users\\Idener\\Downloads\\chromedriver_win32\\chromedriver.exe'
driver = webdriver.Chrome(driver_path, options=options)
url = "https://pubchem.ncbi.nlm.nih.gov/compound/2078"
driver.get(url)
wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.ID, "page-download-btn"))).click()

my selenium driver keeps crashing even though it gets me to the page i want but crashes before it can click the download buttonn

import time
from selenium import webdriver
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.webdriver.support.select import Select
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import TimeoutException
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from bs4 import BeautifulSoup
import pandas as pd
import requests
from selenium.webdriver import Chrome
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(options=options)
driver.get('https://www.nasdaq.com/')
driver.maximize_window()
wait = WebDriverWait(driver, 15)
wait.until(EC.element_to_be_clickable((By.XPATH, '//*[#id="find-symbol-input"]'))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, '//*[#id="find-symbol-input"]'))).clear()
driver.find_element(By.ID, "find-symbol-input").send_keys("GLD")
wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[2]/div/main/div[2]/div[2]/section[1]/div/div[1]/div[1]/form/div/div/div/a[1]'))).click()
driver.implicitly_wait(15)
wait.until(EC.element_to_be_clickable((By.XPATH, "/html/body/div[3]/div/main/div[2]/div[4]/div/section/div/div[3]/ul/li[2]/a/span"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "/html/body/div[3]/div/main/div[2]/div[4]/div/section/div/div[3]/ul/li[2]/a/span"))).clear()
driver.implicitly_wait(10)
wait.until(EC.element_to_be_clickable((By.XPATH, '//*[#id="table-tabs__tab table-tabs__tab--active"]'))).click()
driver.quit()
** not sure what i am doing wrong any feedback is helpful thank you**

Selenium Instagram Login - Unable to locate element

from selenium import webdriver
userName = "myusername123"
driver = webdriver.Chrome()
driver.get("https://www.instagram.com/")
driver.find_element_by_xpath('//*[#id="loginForm"]/div/div[1]/div/label/input').send_keys(userName)
Error
Unable to locate element: {"method":"xpath","selector":"//*. [#id="loginForm"]/div/div[1]/div/label/input"}
I'm trying to make a login in Instagram using selenium but I can't reach the username box with XPath
You could check with the explicitWait and use the name attribute
username=WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.XPATH,"//input[#name='username']")))
username.send_keys("userName")
password=WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.XPATH,"//input[#name='password']")))
password.send_keys("password")
import
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium import webdriver
See, there is name attribute available, you can try with that as below :-
driver.find_element_by_name('username').send_keys(userName)
name is always a reliable locator than xpath
if the above does not work, you can try with the Explicit waits as well :-
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
userName = "myusername123"
driver = webdriver.Chrome()
driver.get("https://www.instagram.com/")
wait = WebDriverWait(driver, 20)
wait.until(EC.element_to_be_clickable((By.NAME, 'username'))).send_keys(userName)
wait.until(EC.element_to_be_clickable(( By.NAME, "password"))).send_keys('somepassword')
wait.until(EC.element_to_be_clickable(( By.XPATH, "//div[text()='Log In']/.."))).click()

How can i make that this program fills in the Form?

Recently i have began with Selenium in Python with Chromium Webdriver, but it doesn't fill in the Login Screen, what did i wrong? I think it has to be with the "find_element" function. Here's 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.Chrome()
driver.get("https://instagram.com")
print(driver.title)
input_username = driver.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[2]/div/label/input")
input_username.send_keys("lowity")
time.sleep(5)
input_paswd = driver.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[3]/div/label/input")
input_paswd.send_keys("password")
time.sleep(5)
button_login = driver.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[4]/button")
button_login.click()
time.sleep(5)
time.sleep(10)
driver.quit()
And the console has no error output.
You have to wait for element being clickable in order to click it. The best way is to user the WebdriverWait() function with until(EC.element_to_be_clickable) Here is the updated 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
driver = webdriver.Chrome(executable_path = 'C:\\chromedriver.exe')
driver.get("https://instagram.com")
print(driver.title)
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[2]/div/label/input"))).send_keys("lowity")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[3]/div/label/input"))).send_keys("janosch2005")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[4]/button"))).click()
driver.quit()

Categories