I am trying to login Naukri using python and selenium, I was able to access the login button using Xpath from the website https://www.naukri.com/, but I am unable to populate my mail ID in Email ID / Username, in the needed box. code I wrote
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://www.naukri.com/')
login = driver.find_element_by_xpath('//*[#id="login_Layer"]/div')
login.click()
userName = driver.find_element_by_xpath('//*[#id="root"]/div[2]/div[2]/div/form/div[2]/input')
userName.send_keys('jones1234#gmail.com')
I dont know, if I have the correct Xpath or not, my maild ID is not getting populated in. I think I have the incorrect Xpath, but I am not sure kindly help.
Add some wait prior to finding the element. You need to allow the element to popup after clicking the login.
wait = WebDriverWait(driver, 10)
driver.get('https://www.naukri.com/')
login = driver.find_element_by_xpath('//*[#id="login_Layer"]/div')
login.click()
userName=wait.until(EC.element_to_be_clickable((By.XPATH,'//*[#id="root"]/div[2]/div[2]/div/form/div[2]/input')))
userName.send_keys('jones1234#gmail.com')
Import
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 am trying to log into twitter to access direct messages. And I need to automate the process using selenium. To do this I have to log in to twitter and authorize my app.
driver = webdriver.Chrome(service=s)
# Selenium opens up webpage
driver.get("https://twitter.com/i/flow/login?input_flow_data=%7B%22requested_variant%22%3A%22eyJoaWRlX21lc3NhZ2UiOiJ0cnVlIiwicmVkaXJlY3RfYWZ0ZXJfbG9naW4iOiJodHRwczovL3R3aXR0ZXIuY29tL2kvb2F1dGgyL2F1dGhvcml6ZT9zdGF0ZT12RkpVMVdDVmYxTDNlVlpqQUU0Z1ZWT1hmNmZHSkEmcmVzcG9uc2VfdHlwZT1jb2RlJnJlZGlyZWN0X3VyaT1odHRwcyUzQSUyRiUyRnd3dy5zcG9ydHNkYXRhbm93LmNvbSUyRiZzY29wZT1kbS5yZWFkJTIwdHdlZXQucmVhZCUyMHVzZXJzLnJlYWQlMjBvZmZsaW5lLmFjY2VzcyZjbGllbnRfaWQ9YUVGMVdYWnZhVzB5WlVKTFV6STFTMFV4VGt3Nk1UcGphUSZjb2RlX2NoYWxsZW5nZV9tZXRob2Q9UzI1NiZjb2RlX2NoYWxsZW5nZT1MOW9xTGsySnhWQTU2TG85Z3d2T1JMWWJ4cWVMNks0QkZYTW4weXhnNmxFIn0%3D%22%7D")
username_input = driver.find_element(By.NAME, "text")
username_input.send_keys('send username here')
This code is opening the site and then I am trying to enter the username however I get an error that says no such element is found. Any help would be much appreciated.
May you need a bit wait:
username_input = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'text')))
username_input.send_keys('send username here')
Following import:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
I have a question about Selenium.
My idea:
My idea is to make a Python script that logs in to this website.
Selenium sends the username and password to the HTML input field and submits it.
Problem:
My code keeps saying:
Message: no such element: Unable to locate element:
I have tried this code with google.com for example and that works.
Why is this not working with this login page?
Can anybody help me please?
My Python code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
login_URL = ""
driver = webdriver.Chrome()
driver.get(login_URL)
time.sleep(5)
inputElement = driver.find_element_by_name('uname')
inputElement.send_keys(username)
time.sleep(20)
driver.close()
i don't know how it works in pyton, im use js
but try to use xpath
driver.find_element_by_xpath('your xpath') [maybe use 1 more click) ('xpath element').click() - element is active.
and after use send keys
******.send_keys('username')
driver.switchTo().frame(driver.findElement(By.xpath('xpath frame'))) - in js
As already explained, the element is in an iframe. Need to switch to frame to interact with the element.
It would be better apply Explicit waits.
# Imports required:
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
driver.get("https://nl.infothek-sptk.com/isps/infothek/?1043")
wait = WebDriverWait(driver,30)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.NAME,"body_frame")))
wait.until(EC.element_to_be_clickable((By.NAME,"uname"))).send_keys("username#mail.com")
# Code to enter other fields.
# Switch back to default to interact with elements outside the iframe.
driver.switch_to.default_content()
Im creating an Instagram bot in Selenium basically to like certain comments with other Instagram accounts, but Im unable to .click() on the xpath of Instagram's heart in the comment section of a certain comment. I really just need the correct xpath of the heart in Instagram's comment section, and I'll be done with this.
from webdriver_manager.chrome import ChromeDriverManager
from time import sleep
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import urllib
Link = 'https://www.instagram.com/p/CCZDF7YH5Yb/c/17958711199328488/'
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://www.instagram.com/')
driver.implicitly_wait(10)
driver.find_element_by_name('username').send_keys('username') #Changed for the purpose of making this thread
driver.find_element_by_name('password').send_keys('password')
Login = "//button[#type='submit']"
driver.find_element_by_xpath(Login).submit()
sleep(1)
#Logs into Instagram
print ('Logged In')
NotNow = "//button[contains(text(),'Not Now')]"
driver.find_element_by_xpath(NotNow).click()
#Clicks Pop Up
print ('Close Pop Up')
#ISSUE is Below
#CommentHeart = '//*[#id="react-root"]/section/main/div/div[1]/article/div[3]/section[1]/span[1]/button/svg' #THIS XPATH doesn't work?
driver.get(Link)
wait = WebDriverWait(driver, 20)
element = wait.until(EC.element_to_be_clickable((By.XPATH, '/main/div/div[1]/article/div[3]/div[1]/ul/div[2]/ul/div/li/div/span/div/button/svg'))) #THIS XPATH doesn't work
element.click()
#driver.find_element_by_xpath(CommentHeart).click()
print ('Likes Comment')```
This is the xpath I've been using, that doesn't work.
```//*[#id="react-root"]/section/main/div/div[1]/article/div[3]/div[1]/ul/div[2]/ul/div/li/div/span/div/button/svg```
I used the xpath below to find the like button and it works for me
driver.find_element_by_xpath('//*[#id="react-root"]/section/main/div/div[1]/article/div[2]/section[1]/'
'span[1]/button').click()
from what I can see in your code is that you have
/section[1]/span[1]/button/svg
but it should be just
/section[1]/span[1]/button
since you want to click on the button and not svg
I'm trying to log into my twitter account by using selenium. The filling of username and password is working perfectly, but when pressing the login-button nothing happens.
self.driver.find_element_by_xpath('//*[#id="react-root"]/div/div/div[2]/main/div/div/form/div/div[3]/div').click()
I looked into the html-code and the aria-haspopup is on false. Is there any way I can set it on true so I can click the button?
Greets
Your xpath is working well on twitter's login page (https://twitter.com/login). Maybe you're trying to login on other page.
I'm providing small piece of code for logging into twitter. I used another xpaths and WebDriverWait for waiting until login form would be displayed.
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.Chrome()
driver.get('https://twitter.com/login')
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//input[#name='session[username_or_email]' and #data-focusable='true']")))
driver.find_element_by_xpath("//input[#name='session[username_or_email]' and #data-focusable='true']").send_keys('login')
driver.find_element_by_xpath("//input[#name='session[password]' and #data-focusable='true']").send_keys('password')
driver.find_element_by_xpath("//div[#data-testid='LoginForm_Login_Button']").click()
Try to do it like this:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.get('https://twitter.com/login')
email = driver.find_element(By.NAME, 'email')
email.clear()
email.send_keys(EMAIL)
password = driver.find_element(By.NAME, 'pass')
password.clear()
password.send_keys(PASSWORD)
password.send_keys(Keys.RETURN) # Login with ENTER button
My ultimate goal is to simply login but there's 2 problem:
My code is unable to detect the ID to input email/password
The random characters in ID value keeps changing (id=login-email_k9et69del)
Your assistant will be greatly appreciated!
#from selenium.webdriver.common.keys import Keys
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
#create Chrome session
driver = webdriver.Chrome("C:\chromedriver.exe")
driver.get('https://www.jetblue.com/signin')
#login
#wait.until(EC.visibility_of_element_located((By.id, "emailLabel")));
username = driver.find_element_by_id("email").send_keys("xxx#gmail.com")
password = driver.find_element_by_id("Password").send_keys("xx")
screenshot inspect
The Id's that you are using are not correct.
You can use the below locators.
driver.find_element_by_css_selector("input[type='email']").send_keys("email goes here")
driver.find_element_by_css_selector("input[type='password']").send_keys ("password goes here")
You can check if the locators is correct in the browser dev tools. Check this post to know how to work with dev tools in browser dev tools.