I have tried to log in a portal of Wifi automatically using python. However, find_element_by_X gives errors.
I am using Chrome as a browser.
from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get('https://hinet.hiroshima-u.ac.jp/loginweb.html')
time.sleep(2)
#driver.find_element_by_css_selector('a.button').click()
username = driver.find_element_by_css_selector("input")
username.clear
#Enter HiroshimaU ID
username.send_keys('input_username')
password = driver.find_element_by_name('pwd')
password.clear
password.send_keys('input_userpassword')
This code should work, but it just gives me errors:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"input"}
I have tried other methods, such as by_name or by_id. But none of them is working.
I am a very beginner so my question might not be clear, but I appreciate your help.
Edit(Oct 23, 2019):
I am sorry you cannot access the portal site.
I hope this screenshot may help.
Portal site
Input is not a valid cssSeletor.
You need top do something like below:
Example:
for https://www.google.com/ website,
cssSeletor of textFiled would be
input[name='q']
First, I couldn't get access to the site you mentioned, as it helps to see how the html formed.
Second based on that, I ask you to have a look at python selenium find_element_by_name
It shows how to access element by name as:
elem=browser.find_element_by_name("Email")
where you can see in the html the name tag of "Email"
Related
Just began typing following code:
from selenium import webdriver
browser = webdriver.Chrome('C:\\webdrivers\\chromedriver.exe')
browser.get('https://auth.sketchengine.eu/#login')
button = browser.find_element_by_xpath('//*[#id="r_0"]')[0]
button.send_keys('Lobster')
button = browser.find_element_by_xpath('//*[#id="r_1"]')[0]
button.send_keys('123123123')
to make Python go to Sketch Engine and type in a login and password. I used inspect in Chrome and then copied the Xpaths, but Python is not doing the typing and says 'unable to locate element' for both the Xpaths. What do I change?
I am not a Python person but try this for xpath. I think the issue is that id "r_0" is on the page a few times. If you look at the xpath with "//input" you will only return one.
//input[#id="r_0"]
//input[#id="r_1"]
I am trying to login into openload.co using python Selenium Chrome Driver but I am getting the following error:
Message: element not interactable
I am using the following code and the error occurs in the last line of the code where I am not able to send the keys to the input tag.
from selenium import webdriver
path="path_to_chrome_driver" #add chromedriver path
driver=webdriver.Chrome(path)
from selenium.webdriver.common.keys import Keys
driver.get('https://openload.co/login')
email = driver.find_element_by_xpath('//*[#id="loginform-email"]')
email.send_keys("example#xyz.com")
I searched for the problem on stackoverflow and landed on the following link similar question which says that probably it is not pointing to correct xpath or css_selector. But I can't seem to find it.
What wrong am I doing here?
It's because there's a modal in the HTML made visible when you click the top right "Sign in" button. There's a duplication of ids. Could you try passing the password and username like this http://username:password#openload.co/ ?
#john try this, works for me:
driver.get('https://openload.co/login')
emails = driver.find_elements_by_xpath('//*[#id="loginform-email"]')
emails[1].send_keys("example#xyz.com")
Try to click on the element before sending keys.
driver.find_element_by_xpath('//*[#id="loginform-email"]').click()
Because of this the cursor will be active on the email textbox field so the element should interactivable.
There are two forms on page: first one for SignIn, second for LogIn. Both have input fields with the same #id values. You need to select form for LogIn:
email = driver.find_element_by_xpath('//h1[.="Login"]/following::*[#id="loginform-email"]')
email.send_keys("example#xyz.com")
So I have been trying to create a selenium script that helps me Log in with facebook for spotify online. The page looks as follows.
The login link is within 2 divs. I have tried to fetch these by class names or the text in them which says "Log in with Facebook" But it does not help and gives me an error saying
Message: no such element: Unable to locate element: {"method":"link text","selector":"Log in with Facebook"}
How do I select the login with facebook button and click on it?
Link text is in all uppercase:
driver.find_element_by_link_text('LOG IN WITH FACEBOOK').click()
You can also use class instead, which is a better selector than link text. Try this:
driver.find_element_by_class_name('btn-facebook').click()
I keep getting the error message below every time I try to insert text into CodeMirror on my webpage. Does anyone know how to successfully edit codemirror with selenium?
WebDriverException: Message: unknown error: Cannot read property 'setValue' of undefined
This is my Selenium-Python code
def click_component_script_editor(self):
driver = self.driver
line18Edit = self.driver.find_element(By.XPATH, "//html//div[#class='CodeMirror-line']//div[18]/pre[1]")
driver.execute_script("arguments[0].CodeMirror.setValue(arguments[1]);",
line18Edit,
"foo.bar")
Figured out the answer to this one, I had to use actionChains instead of just regular old send_keys.
codeMirror = self.driver.find_element(".CodeMirror")
action_chains.click(codeMirror).perform()
action_chains.send_keys("Hello World").perform()
I'm trying to log in to http://sports.williamhill.com/bet/en-gb using python and selenium.
Here is what I've tried so far:
from selenium import webdriver
session = webdriver.Chrome()
session.get('https://sports.williamhill.com/bet/en-gb')
# REMOVE POP-UP
timezone_popup_ok_button = session.find_element_by_xpath('//a[#id="yesBtn"]')
timezone_popup_ok_button.click()
# FILL OUT FORMS
usr_field = session.find_element_by_xpath('//input[#value="Username"]')
usr_field.clear()
WebDriverWait(session, 10).until(EC.visibility_of(usr_field))
usr_field.send_keys('myUsername')
pwd_field = session.find_element_by_xpath('//input[#value="Password"]')
pwd_field.clear()
pwd_field.send_keys('myPassword')
login_button = session.find_element_by_xpath('//input[#id="signInBtn"]')
login_button.click()
I'm getting the following error.
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
when trying to execute
usr_field.send_keys('myUsername')
The usr_field element seems to be visible if I'm viewing it with the inspector tool, however I'm not 100% sure here.
I'm using this script (with some modifications) successfully on other sites, but this one is giving me a real headache and I can't seem to find the answer anywhere on the net.
Would appreciate if someone could help me out here!
The following code will resolve the issue.
from selenium import webdriver
session = webdriver.Chrome()
session.get('https://sports.williamhill.com/bet/en-gb')
# REMOVE POP-UP
timezone_popup_ok_button = session.find_element_by_xpath('//a[#id="yesBtn"]')
timezone_popup_ok_button.click()
# FILL OUT FORMS
user_element = session.find_element_by_name("tmp_username")
user_element.click()
actual_user_elm = session.find_element_by_name("username")
actual_user_elm.send_keys("myUsername")
password_element = session.find_element_by_id("tmp_password")
password_element.click()
actual_pass_element = session.find_element_by_name("password")
actual_pass_element.send_keys("myPassword")
login_button = session.find_element_by_xpath('//input[#id="signInBtn"]')
login_button.click()