Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Instagram';s的“发表评论”按钮不起作用?Python中的硒_Python_Selenium_Post_Button_Instagram - Fatal编程技术网

Instagram';s的“发表评论”按钮不起作用?Python中的硒

Instagram';s的“发表评论”按钮不起作用?Python中的硒,python,selenium,post,button,instagram,Python,Selenium,Post,Button,Instagram,此代码登录Instagram帐户后,会在您的时间轴上的第一篇帖子下方留下评论并发布。但我无法在我的另一个帐户上发表评论。使用.send_键(keys.Enter)可以很好地处理任何其他注释。因此,我尝试在“Post”所在的按钮的XPath上使用.click()和.submit(),但它没有发布。有时它甚至不会发送错误消息。您应该将Post按钮的Xpath更改为: from webdriver_manager.chrome import ChromeDriverManager from selen

此代码登录Instagram帐户后,会在您的时间轴上的第一篇帖子下方留下评论并发布。但我无法在我的另一个帐户上发表评论。使用.send_键(keys.Enter)可以很好地处理任何其他注释。因此,我尝试在“Post”所在的按钮的
XPath
上使用.click()和.submit(),但它没有发布。有时它甚至不会发送错误消息。

您应该将Post按钮的Xpath更改为:

from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.common.keys import Keys

user = 'username'
passw = 'password'



driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://www.instagram.com/')
driver.implicitly_wait(10)

driver.find_element_by_name('username').send_keys(user)
driver.find_element_by_name('password').send_keys(passw)
Login = "//button[@type='submit']"
sleep(2)
driver.find_element_by_xpath(Login).submit()
sleep(1)
# Logs into Instagram
print ('Logged In')

#------------------------ATTENTION

NotNow = "//button[contains(text(),'Not Now')]"
driver.find_element_by_xpath(NotNow).click()
# Clicks Pop Up
print ('Close Pop Up')

# It's weird but the pop up opens once, only after this page.
# If ever a problem delete one, or have the first click be
# directed to your Instagram Profiles timeline

NotNow = "//button[contains(text(),'Not Now')]"
driver.find_element_by_xpath(NotNow).click()
#Clicks Pop Up
print ('Close Pop Up')

#-----------------------------------



driver.refresh()
print ('refreshing')
driver.implicitly_wait(10)


LeaveComment = driver.find_element_by_xpath("//div/form[*[local-name()='textarea']]")
LeaveComment.click()

LeaveComment2 = driver.find_element_by_tag_name('textarea')
LeaveComment2.send_keys("look at this @programmer.chad nice post!")

#Xpath of the Post button on Instagram
Post = "//div/form/[*[local-name()='button']/@type='submit']"

#Xpath of the Form where the Post button is located
Form = "//div[*[local-name()='form']]"

#LeaveComment2.send_keys(Keys.ENTER)

#ERROR IS BELOW
driver.find_element_by_xpath(Post).submit()
并更改此函数
驱动程序。通过xpath(Post)查找元素。提交()

这是一个
驱动程序。通过xpath(Post)查找元素。单击()。。。。。谢谢你。第[3]节有时会变成Instagram上的第[2]节,因此我可能需要为此做好准备。谢谢你
Post = '//*[@id="react-root"]/section/main/section/div/div[2]/div/article[1]/div/div[3]/section[3]/div/form/button'