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
Related
This is what the alert looks like. It reads: The proxy it3.prmsrvs.com is requesting a username and password I have a program in Selenium that automates a certain amount of stuff on a website.
For some reason (this has been encountered also by my colleagues when using the browser normally without automation) there is the possibility of a pop-up showing in the webpage at a random point.
My program's objective is to load a page, get a list of all the elements corresponding to a specific tag and then click on them one by one. They all open in a new tab.
There is the possibility of a pop-up to show in the page after closing one of the tabs.
This pop-up asks for a login but all I have to do is dismiss it and the page will keep working like always.
Now, I've seen people using driver.switch_to.alert.dismiss() but this doesn't seem to work on this page.
I checked the function on a very basic js alert and the dismiss works perfectly, so I think it's the type of alert that is the issue.
I can't inspect the page so I don't know how to retrieve the iFrame of this alert. (I saw this as a possible solution online)
What should I do?
I'm trying to scrape my Instagram DMs (direct messages). However, I don't know how to automate scrolling down the column to get the additional usernames that messaged me.
I've tried this, as well as the scrolling code listed here.
However, neither work because Instagram's DM page is broken into columns. The full page itself does not need to be scrolled. Just the first column. For reference, here's a screenshot of what the Instagram DM page looks like. I blocked out my username and the usernames of people who DMed me for privacy reasons
Does anyone have any ideas on how I can modify the script that scrolls down the page to accommodate the column size?
Thank you for taking the time to read my question and help in any way you can.
You should instead try to use the export data feature on Instagram, you will get the JSON files of all the messages and media you have sent or received. This will make your task a lot easier.
https://help.instagram.com/contact/505535973176353
https://www.instagram.com/download/request/
Instead of targeting the window you should target the messages box element to scroll:
scroll_y = 1000
driver.execute_script(f"document.getElementsByClassName('N9abW')[0].scrollTo(0,{scroll_y})")
if it doesn't work with class name try with Xpath:
path = "//*[#id='react-root']/section/div/div[2]/div/div/div[1]/div[2]/div/div/div"
script = f"document.evaluate({path}, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.scrollTo(0,{scroll_y});"
driver.execute_script(script)
Adjust scroll if needed
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
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 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']"));