Reputation: 154
in feature file when I want to pass multiple condition in xpath then I am getting 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 |
The StepDefination code is as below -
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)
The Exception is as below -
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'
The SPACE is not allowing in xpath.
Please let me know how to pass multiple condition in xpath in feature file
Upvotes: 2
Views: 275
Reputation: 474221
One quick workaround would be to specify multiple conditions this way:
//input[@name='q'][@class='gsfi']
Or, I think, putting the placeholder into backticks should solve the space escaping issue:
@given(u'Enter value in google `{x_pth}` and {g_val}')
Upvotes: 1