Selenium Python3 - 属性错误:'str'对象没有属性'tag_name'



使用Selenium/Python进行自动化的新手。我无法自动填写注册表格。下拉是必需的元素,但我得到以下错误…

AttributeError: 'list'对象没有属性'tag_name'

我把我的代码贴在下面,在网上找不到任何答案,为什么会这样。非常感谢任何/所有的帮助。

from re import X
from socket import timeout
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from locale import currency
from operator import index
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from unicodedata import name
import pandas as pd
import csv
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait 
web = webdriver.Chrome("/home/nosra/chromedriver")
#class selenium :webdriver.support.wait.WebDriverWait(web, timeout, poll_frequency=0.5, ignored_exceptions=None)

df=pd.read_excel('info1.xlsx')
url=["https://docs.google.com/forms/d/e/1FAIpQLScGMoYVsxtsQ0Je4RTYEZndWrKkdt5jJwXBcMAcOia2WuIRtA/viewform?usp=sf_link"]
for link in url:  
for i in df.index :
web.get(link)
entry=df.loc[i]     
name=web.find_element(By.XPATH,"//*[@id='mG61Hd']/div[2]/div/div[2]/div/div/div/div[2]/div/div[1]/div/div[1]/input")
time.sleep(1)
name.send_keys(entry['name'])
time.sleep(1)
lastName=web.find_element(By.XPATH,"//*[@id='mG61Hd']/div[2]/div/div[2]/div[2]/div/div/div[2]/div/div[1]/div/div[1]/input")
time.sleep(2)
lastName.send_keys(entry['lastName '])

select_C=Select(web.find_elements(By.XPATH,"//*[@id='mG61Hd']/div[2]/div/div[2]/div[3]/div/div/div[2]/div/div[1]/div[1]/div[3]/span"))
select_C.select_by_index(1)```

select_C定义错误:您应该将单个WebElement传递给Select(因此您需要使用web.find_element而不是web.find_elements),并且您的XPath应该获取select节点而不是spanSelect类在这里不适用。点击

web.find_element('xpath', '//div[@role="option"]').click()

打开下拉菜单,然后

web.find_element('xpath', '//div[@data-value="Tunisia" and @aria-selected="false"]').click()

选择选项

相关内容

  • 没有找到相关文章

最新更新