我使用该脚本与Python中的网站进行WhatsApp集成。 为什么“我的脚本”无法正常工作,您能否在联系方式中检查我是否维护我的联系人文件,而使用ipdb作为跟踪代码时,它会在第30行显示错误。
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome('./chromedriver')
driver.get('https://web.whatsapp.com/')
wait = WebDriverWait(driver, 600)
with open("contact") as f:
for line in f:
try:
name = (line.rstrip('\n'))
text = """Hello {}, My name is Rhevin
Have a good day :)
""".format(name)
print 'Harish'
inp_xpath_search = "//input[@title='Search or start new chat']"
input_box_search = wait.until(EC.presence_of_element_located((
By.XPATH, inp_xpath_search)))
print '@@@@@@@@@@@@@@@@',input_box_search
input_box_search.send_keys(name + Keys.ENTER)
#x_arg_contact = '//div[@class="chat-title"]'
x_arg_contact = '//span[contains(@title,' + name + ')]'
input_box_contact = wait.until(EC.presence_of_element_located((
By.XPATH, x_arg_contact)))
print '-------------------',input_box_contact
inp_xpath = "//div[@contenteditable='true']"
input_box = wait.until(EC.presence_of_element_located((
By.XPATH, inp_xpath)))
print '+++++++++++++++++++++++',input_box
input_box.send_keys(text + Keys.ENTER)
print '==============================='
time.sleep(5)
print("send")
except:
print("error")