0
votes

I am trying to use selenium with python and am running into an issue when trying to use the webdriver.expectedConditions class.

The following code is excerpted from a couple of classes, but all necessary code is included:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

def isVisible(self, driver, HOW, WHAT, timeout=2):
    locator=(HOW,WHAT)
    try:
        WebDriverWait(driver, timeout).until(EC.visibility_of_element_located(locator))
        return True
    except TimeoutException:
        return False

newApplicationXpath = "//input[@value='New']"
self.assertTrue(self.isVisible(self.driver, "By.XPATH",     newApplicationXpath, 120))

Traceback:

WebDriverException: Message: unknown error: Unsupported locator strategy: By (Session info: chrome=66.0.3359.139) (Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Linux 4.1.12-112.14.10.el7uek.bug27766149.x86_64 x86_64)

1

1 Answers

2
votes

Without having more code to go off of (the sample you provided is very incomplete), I'm going to assume your error is because you're passing "By.XPATH" as a string, rather than as By.XPATH. Change the last line of your code to:

self.assertTrue(self.isVisible(self.driver, By.XPATH, newApplicationXpath, 120))