gpt4 book ai didi

java - python 行为 :feature file : xpath issue

转载 作者:行者123 更新时间:2023-11-30 10:31:02 25 4
gpt4 key购买 nike

在功能文件中,当我想在 xpath 中传递多个条件时,我得到 selenium.common.exceptions.InvalidSelectorException

Feature: showing off behave

Scenario Outline: run a simple test
Given we have behave installed <thing> and <good>
And Enter value in google <x_path> and <g_val>

Examples:
| thing | good | x_path | g_val |
| Red Tree Frog | Hello Automation | //input[@name='q' and @class='gsfi'] | hello world |

StepDefination代码如下-

from behave import given
from selenium import webdriver

driver = webdriver.Ie("C:\\Users\\ksahu\\Downloads\\IEDriverServer_x64_3.3.0\\IEDriverServer.exe")
driver.implicitly_wait(15)

@given(u'we have behave installed {thing} and {good}')
def step_impl(context,thing,good):
print('============> '+thing+'===========> '+good)

@given(u'Enter value in google {x_pth} and {g_val}')
def step_impl(context,x_pth,g_val):
driver.get("http://www.google.com")
driver.maximize_window()
print(x_pth)
#driver.find_element_by_name(x_pth).send_keys(g_val)
driver.find_element_by_xpath(x_pth).send_keys(g_val)

异常如下-

selenium.common.exceptions.InvalidSelectorException: Message: Unable to locate an element with the xpath expression //input[@name='q'\ and\ @class='gsfi'] because of the following error:
Error: Bad token, expected: ] got: \


Captured stdout:
=============> Red Tree Frog==========> Hello Automation
//input[@name='q'

SPACE 在 xpath 中是不允许的。

请让我知道如何在特征文件的 xpath 中传递多个条件

最佳答案

一个快速的解决方法是以这种方式指定多个条件:

//input[@name='q'][@class='gsfi']

或者,我认为,将占位符放入反引号 应该可以解决空格转义问题:

@given(u'Enter value in google `{x_pth}` and {g_val}')

关于java - python 行为 :feature file : xpath issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43450848/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com