I'm trying to write a program in python with which I open gmail, log in, and send an email from my account. The only problem is I can't find the name or id of any of the buttons I need to have either a name or id for. Can anyone help me with this? I'm sorry if this question is considered too simplistic but I have been looking all through the code I can see and I can't seem to find it. I can seem to do everything I need to do for this program except this. Thank you.
Edit: I have been using Selenium. Basically how the program will work is it opens my browser, goes to gmail, inputs my email in the appropriate box, clicks the button to move on, inputs my password in the appropriate box, and clicks the button to sign in. Then it clicks the "compose email" button and inputs text then clicks the "send" button. I've already basically made it work apart from the buttons which is the issue.
Edit:
def openGmail():
from selenium import webdriver
import time
driver = webdriver.Chrome('/Users/elliot/Desktop/chromedriver')
driver.get('http://www.gmail.com');
signinbox = driver.find_element_by_name('identifier')
signinbox.send_keys('myemail#gmail.com')
signinbutton = driver.find_element_by_id('identifierNext')
signinbutton.click()
time.sleep(1)
passwordbox = driver.find_element_by_name('password')
passwordbox.send_keys('mypassword')
passwordbutton = driver.find_element_by_id('passwordNext')
passwordbutton.click()
in google or secure website similar to that, they don't use buttons basically
so what you can do is use css selectors in selenium
example
WebElement nxtBtn = driver.findElement(By.cssSelector("*[text='Next']"));
or
WebElement nxtBtn = driver.findElement(By.cssSelector("*[innertext='Next']"));
Related
I am trying to code a program for somebody, that is possible to send and delete messages at the same time in the browser Discord application.(I think he wants to use this to spam?) He told me to write the code in Python, so I used python with Selenium. At this point I got everything working so far, the login works, the channel select works if you just insert the channel link directly. It also managed to let it send some messages. But problem now is, that I don't know how to delete the message after it was send, beacuse you need to click a "More" button first. But this more Button
I would use Webbot for that:
from webbot import Browser
web = Browser()
web.click('More')
that module has quite a few useful simple functions so i encourage you to try it
just started with both python and selenium and i'm trying to make a script that logs into facebook, then searches for certain person and sends some message, but i have no idea how do i focus facebook's message div. tried both
browser.execute_script("document.querySelector('._1mf').click();")
and
searchBar = browser.find_element_by_class_name('_4po3')
but it seems like the right element loads after you click on the messagebox so i tried multiple different classnames and still i'm stucked :/
EDIT: just to be clear
i managed to grab specific person from the chat bar by
searchBarAfterUpdate = browser.find_element_by_xpath(
"//div[#class = '_364g' and text() = 'personname']")
searchBarAfterUpdate.click()
and now when i have the chat box open i want to somehow write and send a message
I try to login a site automatically by selenium.
My script sometimes works smoothly but sometimes it does not send full-text of user name or passwork to relavant inputs so it then failed to login.
I try to insert implicitly_wait but it appears not to solve this problem totally.
I wonder if there is any function to require the webdriver to fullfill each of input before excecute another one in selenium.
Here is may attempt:
browserdriver.get(url)
#fill username
browserdriver.implicitly_wait(25)
psusername=browserdriver.find_element_by_xpath("//*[#class='form-group'][1]/input[#name='username']")
psusername.click()
psusername.send_keys("1234567890")
#fill password
browserdriver.implicitly_wait(25)
pspass=browserdriver.find_element_by_xpath("//*[#class='form-group'][2]/input[#name='password']")
pspass.click()
pspass.send_keys("abcdefgfk12345")
browserdriver.implicitly_wait(25)
pssubmit=browserdriver.find_element_by_xpath("//*[#class='login-btn']/button[#type='submit']")
pssubmit.click()
Pls, explain for me why I get stuck on this problem and how to solve it! thanks alot
EDIT1: I add the target site address: click here You should click on login words (Đăng nhập) on the top right screen to see the popup login pannel.
EDIT 2: Thank to guide of below comments, I try to add some code lines to force it to key individual letter and it appears to work well so I add solution here:
text_input="1234567890"
for i in text_input:
psusername.send_keys(i)
Use set attribute instead of sendkeys
here is the example code:
webdriver.executeScript("document.getElementById('elementID').setAttribute('value', '1234567890')");
I am using selenium to automate repetitive task. It works really well. But I ran into a issue where I get an email sent to me which has a download button in it. I am not sure how to click on it? I can get the xpath but that only works once. Any help would be great!
Here is the button I am trying to select
Email's button
download_button = driver.find_element_by_xpath('//*[#id="m_-2340741114430056650background-table"]/tbody/tr/td/table/tbody/tr[4]/td/table/tbody/tr/td[2]/table/tbody')
The xpath only works once after I grab that specific path. The idea is that this email is sent every week and for me to automatically select the button for the download. There isn't other identifiers like name or id, etc for this element. The email is sent from another company, so I don't think I have access to changing the way it is sent.
Please let me know if you need more information. Thank you for any help.
I'm having trouble logging into a website using Selenium via Python.
I'm new to web scraping and as part of the learning process I'm attempting to web scrape my account activity from American Airlines with Python. This requires logging in, which is where my code (see below) fails. All the form fields are populated, however, when I submit, the page just seems to refresh and clears my entries.
Checks I've perform:
Login information is correct. I've manually logged in.
I've played around with different lengths for sleep time. No success
Cleared form prior to entry. No success
Run the code up to (but no including) the submit() line, and then manually click the "Log In" button. Login still fails. This makes me think that the fields are somehow populated incorrectly, but I can't see where the issue is.
Thanks in advance for any help!
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Chrome()
driver.get("https://www.aa.com/homePage.do")
loginId = driver.find_element_by_name("loginId")
lastName = driver.find_element_by_name("lastName")
password = driver.find_element_by_name("password")
time.sleep(2)
loginId.send_keys("my-email-here")
lastName.send_keys("my-last-name-here")
password.send_keys("my-password-here")
time.sleep(2)
password.submit()
I believe that AA and other airlines have sophisticated bot detection that know you are using selenium to find and manipulate elements in the DOM, causing the page to navigate back to login. Even if I do a:
driver.find()
on the webpage and fill out the fields myself it fails, but if I do just a:
driver.get('https://www.aa.com')
and then fill out the fields it will allow me to continue. I have found a few posts on google and reddit that have gone over this if you do some searching. Also Can a website detect when you are using selenium with chromedriver? , goes over some of the ways they might be doing it.