can';t在selenium python中向元素中输入文本
为什么在尝试将文本输入到角度输入元素时会出现“InvalidArgumentException”。 注意:我从csv文件获取xpathcan';t在selenium python中向元素中输入文本,python,selenium,selenium-webdriver,automation,Python,Selenium,Selenium Webdriver,Automation,为什么在尝试将文本输入到角度输入元素时会出现“InvalidArgumentException”。 注意:我从csv文件获取xpath class TimeSheet: def __init__(self): c_options = Options() self.__driver = webdriver.Chrome(options=c_options) self.__action = None def enter_text_i
class TimeSheet:
def __init__(self):
c_options = Options()
self.__driver = webdriver.Chrome(options=c_options)
self.__action = None
def enter_text_into_element(self):
text = self.__action['enter_text']
element = self.__driver.find_element_by_xpath(self.__action['xpath'])
element.clear()
print('text cleared')
element.send_keys(text)
def click_function(self):
click_status = False
element_clicked = self.__driver.find_element_by_xpath(self.__action['xpath'])
try:
element_clicked.click()
click_status = True
except Exception as ex:
print(ex)
return click_status
ts = TimeSheet()
for index, task in enumerate(tasks):
ts.set_action(task)
print(ts.get_step(), end=": ")
print(ts.get_action())
if ts.get_action() == 'click':
ts.click_function()
elif ts.get_action() == 'text':
ts.enter_text_into_element()
#错误回溯
回溯(最近一次调用上次):文件
“C:\PycharmProjects\testSelenium\timesheet_automation.py”,第116行,
在里面
ts.在第82行的文件“C:\PycharmProjects\testSelenium\timesheet\u automation.py”中输入\u text\u
在元素中输入文本
element=self.\u驱动程序。通过xpath(self.\u操作['xpath'])文件查找元素
“C:\PycharmProjects\testSelenium\venv\lib\site packages\selenium\webdriver\remote\webdriver.py”,
第394行,按xpath查找元素
返回self.find_元素(by=by.XPATH,value=XPATH)文件“C:\PycharmProjects\testSelenium\venv\lib\site packages\selenium\webdriver\remote\webdriver.py”,
第976行,在find_元素中
返回self.execute(Command.FIND_元素,{File“C:\PycharmProjects\testSelenium\venv\lib\site packages\selenium\webdriver\remote\webdriver.py”,
执行中的第321行
self.error\u handler.check\u响应(response)文件“C:\PycharmProjects\testSelenium\venv\lib\site packages\selenium\webdriver\remote\errorhandler.py”,
第242行,在check_响应中
引发异常类(消息、屏幕、堆栈跟踪)selenium.common.exceptions.InvalidArgumentException:消息:无效
参数:缺少命令参数
请包含完整的回溯您可以立即检查回溯看起来您的xpath无效。在使用xpath进行搜索之前打印xpath。您的浏览器/驱动程序版本是什么?它们是否同步?我使用的是chrome浏览器和chrome驱动程序版本86.0.4240.22