首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否在使用Selenium导航到文本框后填写文本框?

是否在使用Selenium导航到文本框后填写文本框?
EN

Stack Overflow用户
提问于 2019-10-29 10:05:28
回答 1查看 33关注 0票数 0

我已经设法编写了一个程序,它可以导航到所需的网站,然后单击我想要填写的第一个文本框。我遇到的问题是,我正在使用的send_keys方法没有使用'Testing‘填充所需的文本框,并且我收到了这个错误:

代码语言:javascript
复制
AttributeError: 'NoneType' object has no attribute 'find_elements_by_xpath'

以下是到目前为止的代码:

代码语言:javascript
复制
import selenium
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as Wait
from selenium.webdriver.support import expected_conditions

driver = selenium.webdriver.Chrome(executable_path='path_to_chromedriver')


def get_url(url):
    driver.get(url)
    driver.maximize_window()
    Wait(driver, 30).until(expected_conditions.presence_of_element_located
                           ((By.ID, 'signup-button'))).click()


def fill_data():
    sign_up = Wait(driver, 30).until(expected_conditions.presence_of_element_located
                                     ((By.XPATH,
                                       '/html/body/onereg-app/div/onereg-form/div/div/form/section/section['
                                       '1]/onereg-alias-check/ '
                                       'fieldset/onereg-progress-meter/div[2]/div[2]/div/pos-input[1]'))).click()
    sign_up.send_keys('Testing')


get_url('https://www.mail.com/')
# Find the signup element
fill_data()
EN

回答 1

Stack Overflow用户

发布于 2019-10-29 13:46:07

find_elements_by_xpath`返回所有匹配的元素,这是一个列表,因此您需要遍历并获取每个元素的文本属性

此外,在fill data方法中,您正在尝试为注册表单填充数据,因此您需要标识该表单上的所有元素,并使用您的数据处理表单。

填写电子邮件Id时您的xpath不正确,请更新您的xpath并重试

代码语言:javascript
复制
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 
from selenium.webdriver.support.ui import WebDriverWait as Wait



# Open Chrome
driver = webdriver.Chrome(executable_path='path_to_chromedriver')


def get_url(url):
    driver.get(url)
    driver.maximize_window()



def fill_data():

    Wait(driver, 30).until(EC.element_to_be_clickable
                           ((By.ID, 'signup-button'))).click()

    inputBox = Wait(driver, 30).until(EC.visibility_of_element_located((By.XPATH, "/html/body/onereg-app/div/onereg-form/div/div/form/section/section[1]/onereg-alias-check/fieldset/onereg-progress-meter/div[2]/div[2]/div/pos-input[1]/input")))
    inputBox.send_keys('Testing')


get_url('https://www.mail.com/')
# Find the signup element
fill_data()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58600598

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档