-
Notifications
You must be signed in to change notification settings - Fork 1.4k
-
SelectorSyntaxError: Expected an argument, got <DELIM '^' at 13>
when using hover_on_element("//div[contains(@Class,'field row')]//div[text()='TextInput65691513430']")
Note that the following code works fine:
obj = self.get_element("//div[contains(@class,'field row')]//div[text()='TextInput65691513430']")
hover = ActionChains(self.driver).move_to_element(obj)
hover.perform()
Beta Was this translation helpful? Give feedback.
All reactions
I see the issue.
The current solution is to use one of the following selectors:
XPATH: "//div[contains(@class, 'field row')]//div[contains(., 'TextInput65691513430')]"
Or CSS: 'div[class*="field row"] div:contains("TextInput65691513430")'
I'll make an update to allow for the XPath text()='TEXT'
selector in the long run. Currently, the XPath contains(., 'TEXT')
is the standard for XPath selectors containing text. It'll be shipped in the next release.
Replies: 3 comments 3 replies
-
I see the issue.
The current solution is to use one of the following selectors:
XPATH: "//div[contains(@class, 'field row')]//div[contains(., 'TextInput65691513430')]"
Or CSS: 'div[class*="field row"] div:contains("TextInput65691513430")'
I'll make an update to allow for the XPath text()='TEXT'
selector in the long run. Currently, the XPath contains(., 'TEXT')
is the standard for XPath selectors containing text. It'll be shipped in the next release.
Beta Was this translation helpful? Give feedback.
All reactions
-
New Release: 2.3.13
with the fix: https://github.com/seleniumbase/SeleniumBase/releases/tag/v2.3.13
Hovering will also require a relatively new version of Chromedriver:
sbase install chromedriver latest
Beta Was this translation helpful? Give feedback.
All reactions
-
I upgraded to 2.3.13 and got the following
KeyError: 'capabilities'
self = <tests.test_contacts.ContactsTest testMethod=test_field_under_custom_group_delete>
selector = 'div[class*="field row"] div:contains("TextInput32847084750")'
by = 'css selector'
def hover_on_element(self, selector, by=By.CSS_SELECTOR):
self.__check_scope()
original_selector = selector
original_by = by
selector, by = self.__recalculate_selector(selector, by)
if page_utils.is_xpath_selector(selector):
selector = self.convert_to_css_selector(selector, By.XPATH)
by = By.CSS_SELECTOR
self.wait_for_element_visible(
selector, by=by, timeout=settings.SMALL_TIMEOUT
)
self.__demo_mode_highlight_if_active(original_selector, original_by)
self.scroll_to(selector, by=by)
time.sleep(0.05) # Settle down from scrolling before hovering
if self.browser != "chrome":
return page_actions.hover_on_element(self.driver, selector)
# Using Chrome
# (Pure hover actions won't work on early chromedriver versions)
try:
return page_actions.hover_on_element(self.driver, selector)
venv/lib/python3.9/site-packages/seleniumbase/fixtures/base_case.py:1859:
driver = <selenium.webdriver.chrome.webdriver.WebDriver (session="e67567bde83ea570081c29f348b216fb")>
selector = 'div[class*="field row"] div:contains("TextInput32847084750")'
by = 'css selector'
def hover_on_element(driver, selector, by=By.CSS_SELECTOR):
"""
Fires the hover event for the specified element by the given selector.
@Params
driver - the webdriver object (required)
selector - the locator for identifying the page element (required)
by - the type of selector being used (Default: By.CSS_SELECTOR)
"""
element = driver.find_element(by=by, value=selector)
venv/lib/python3.9/site-packages/seleniumbase/fixtures/page_actions.py:148:
self = <selenium.webdriver.chrome.webdriver.WebDriver (session="e67567bde83ea570081c29f348b216fb")>
by = 'css selector'
value = 'div[class*="field row"] div:contains("TextInput32847084750")'
def find_element(self, by=By.ID, value=None) -> WebElement:
"""
Find an element given a By strategy and locator.
:Usage:
::
element = driver.find_element(By.ID, 'foo')
:rtype: WebElement
"""
if isinstance(by, RelativeBy):
return self.find_elements(by=by, value=value)[0]
if by == By.ID:
by = By.CSS_SELECTOR
value = '[id="%s"]' % value
elif by == By.TAG_NAME:
by = By.CSS_SELECTOR
elif by == By.CLASS_NAME:
by = By.CSS_SELECTOR
value = ".%s" % value
elif by == By.NAME:
by = By.CSS_SELECTOR
value = '[name="%s"]' % value
return self.execute(Command.FIND_ELEMENT, {
'using': by,
'value': value})['value']
venv/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py:1244:
self = <selenium.webdriver.chrome.webdriver.WebDriver (session="e67567bde83ea570081c29f348b216fb")>
driver_command = 'findElement'
params = {'using': 'css selector', 'value': 'div[class*="field row"] div:contains("TextInput32847084750")'}
def execute(self, driver_command: str, params: dict = None) -> dict:
"""
Sends a command to be executed by a command.CommandExecutor.
:Args:
- driver_command: The name of the command to execute as a string.
- params: A dictionary of named parameters to send with the command.
:Returns:
The command's JSON response loaded into a dictionary object.
"""
if self.session_id:
if not params:
params = {'sessionId': self.session_id}
elif 'sessionId' not in params:
params['sessionId'] = self.session_id
params = self._wrap_value(params)
response = self.command_executor.execute(driver_command, params)
if response:
self.error_handler.check_response(response)
venv/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py:424:
Beta Was this translation helpful? Give feedback.
All reactions
-
I see the issue. The error message was incorrect: SeleniumBase 2.3.14
should fix that. That won't remove your issue because you'll still have an out-of-date chromedriver, which you can upgrade with seleniumbase install chromedriver latest
. Upgrading seleniumbase will tell you the exact version to upgrade your chromedriver to in order match with the version of Chrome that you have installed.
Old versions of Chromedriver have broken support for hovering over elements, although an old Chromedriver will be installed by default because there's no matching version requirement with Chrome. Newer versions of Chromedriver require a match to the version of Chrome installed.
Beta Was this translation helpful? Give feedback.
All reactions
-
I upgraded seleniumbase to 2.3.14 and installed the latest chromediver and I have the latest chrome browser. I am still getting invalid selector error message. why is "//div[contains(@Class,'field row')]//div[text()='TextInput65691513430']" an invalid selector ?
Beta Was this translation helpful? Give feedback.
All reactions
-
Use one of the following selectors:
XPATH: "//div[contains(@class, 'field row')]//div[contains(., 'TextInput65691513430')]"
Or CSS: 'div[class*="field row"] div:contains("TextInput65691513430")'
Beta Was this translation helpful? Give feedback.