我想通过他们的网站在Instagram上发送多条消息。到目前为止,我可以登录并打开特定人的dm。我想选择文本框并发送一些输入。我正在尝试这段代码
messageBox = driver.find_element_by_xpath("//*[@class=' Igw0E IwRSH eGOV_
vwCYk ItkAi
']")
messageBox.click()
messageBox.send_keys("test")
send = driver.find_element_by_xpath("//button[@class='sqdOP yWX7d y3zKF ']")
send.click()它引发了一个错误,即元素(messageBox)目前不可交互。
我也尝试过使用javascript输入。
messageBox = driver.find_element_by_xpath("//*[@class=' Igw0E IwRSH eGOV_
vwCYk ItkAi
']")
driver.execute_script("arguments[0].value = 'test';", messageBox)但是,这不会输入任何内容,也不会引发错误。我该怎么办?
发布于 2020-05-14 22:32:05
我认为输入要么是隐藏的,要么是容量设置为0
如果容量设置为0,请尝试此操作
JavascriptExecutor js = (JavascriptExecutor) getDriver();
js.executeScript("document.querySelector(\"yourSelector\").style.opacity='1'");然后尝试对该值执行sendKeys
如果是隐藏输入,请使用以下代码
document.querySelector(\"yourSelector\").style.display ='active'然后尝试对该值执行sendKeys
发布于 2020-05-15 19:25:48
我尝试了很多方法,但最终还是成功了。
messageBox = driver.find_element_by_tag_name("textarea")
messageBox.click()
messageBox.send_keys("test")如果有人想知道,这里是完整的代码
import time
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.instagram.com/")
username = "" #your username
password = "" #password
time.sleep(2)
#login
usernamefield = driver.find_element_by_name("username")
usernamefield.click()
usernamefield.send_keys(username)
passwordfield = driver.find_element_by_name("password")
passwordfield.click()
passwordfield.send_keys(password)
login = driver.find_element_by_xpath("//*[@class=' Igw0E IwRSH eGOV_ _4EzTm ']")
login.click()
time.sleep(5)
popup = driver.find_element_by_xpath("//*[@class='aOOlW HoLwm ']")
popup.click()
driver.get("https://www.instagram.com/direct/inbox/")
time.sleep(2)
#select the first person on your dm list
contact = driver.find_element_by_xpath("//*[@class='-qQT3 rOtsg']")
contact.click()
time.sleep(2)
#send messages in succession
message = "" #your message
for i in range(500):
messageBox = driver.find_element_by_tag_name("textarea")
messageBox.click()
messageBox.send_keys(message)
send = driver.find_element_by_xpath("//*[@class=' Igw0E IwRSH eGOV_ _4EzTm JI_ht ']")
send.click()https://stackoverflow.com/questions/61789030
复制相似问题