mictrn
mictrn

Reputation: 55

trying to use relative locator in selenium with python but it I get 'locate_with' is not defined error

I'm trying to interact with a web element in selenium, I've located a nearby element, the element I want to interact with is to the right of the located element so i tried using the relative locator to do so:

sbJct = driver.find_element(locate_with(By.XPATH, "//span[@role='combobox']").right(term)) webdriver.ActionChains(driver).move_to_element(sbJct).click(sbJct).perform()

When i execute i get

NameError: name 'locate_with' is not defined

I think I may be missing an import but I'm unsure

    from selenium import webdriver
# webdriver.Safari(executable_path='/usr/bin/safaridriver')
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

Upvotes: 1

Views: 896

Answers (1)

mictrn
mictrn

Reputation: 55

I was in fact missing an import, the documentation doesn't mention this but u have to use

from selenium.webdriver.support.relative_locator import locate_with

to use locate_with()

Upvotes: 1

Related Questions