How to use the selenium.webdriver.common.by.By.XPATH function in selenium

To help you get started, we’ve selected a few selenium examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github venkywarriors619 / selenium_with_python / Python_basics / AutomationFramework_Part_1 / 165 4-login-tests.py View on Github external
def test_validLogin(self):
        baseURL = "https://letskodeit.teachable.com/"
        driver = webdriver.Firefox()
        driver.maximize_window()
        driver.implicitly_wait(3)
        driver.get(baseURL)

        lp = LoginPage(driver)
        lp.login("test@email.com", "abcabc")

        userIcon = driver.find_element(By.XPATH, ".//*[@id='navbar']//span[text()='User Settings']")
        if userIcon is not None:
            print("Login Successful")
        else:
            print("Login Failed")
github wgnet / webium / tests / simple_page / __init__.py View on Github external
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webelement import WebElement

import tests
from webium.base_page import BasePage
from webium.controls.checkbox import Checkbox
from webium.controls.image import Image
from webium.controls.link import Link
from webium.controls.select import Select
from webium.find import Find, Finds


class Container(WebElement):
    second_element_with_id = Find(by=By.XPATH, value='.//*[2]')
    empty_element_list = Finds(by=By.XPATH, value='.//a[@no_such_attribute]')


class SpanContainer(object):
    span = Find(by=By.TAG_NAME, value='span')
    empty_element_list = Finds(by=By.XPATH, value='.//a[@no_such_attribute]')


class DivWithLink(WebElement):
    first_link = Find(Link, By.TAG_NAME, 'a')
    '''@type: Link'''


class SimplePage(BasePage):
    one_line = Find(by=By.ID, value='oneline')
    '''@type: WrongType'''
    icon_link = Find(Link, By.ID, 'validAnchorTag')
github freenas / webui / tests / selenium / acc_group.py View on Github external
def error_check(self):
        if function.is_element_present(driver, self, By.XPATH, '//*[contains(text(), "Close")]'):
            if function.is_element_present(driver, self, By.XPATH,'/html/body/div[5]/div[2]/div/mat-dialog-container/error-dialog/h1'):
                ui_element=driver.find_element_by_xpath('/html/body/div[5]/div[2]/div/mat-dialog-container/error-dialog/h1')
                error_element=ui_element.text
                print (error_element)
            driver.find_element_by_xpath('//*[contains(text(), "Close")]').click()
            print ("Duplicate user cannot be created")
        if function.is_element_present(driver, self, By.XPATH, '//*[contains(text(), "Close")]'):
            if function.is_element_present(driver, self, By.XPATH,'/html/body/div[5]/div[2]/div/mat-dialog-container/error-dialog/h1'):
                ui_element=driver.find_element_by_xpath('/html/body/div[5]/div[2]/div/mat-dialog-container/error-dialog/h1')
                error_element=ui_element.text
                print (error_element)
            driver.find_element_by_xpath('//*[contains(text(), "Close")]').click()
            print ("Duplicate user cannot be created")
github wgnet / webium / tests / simple_page / __init__.py View on Github external
from webium.base_page import BasePage
from webium.controls.checkbox import Checkbox
from webium.controls.image import Image
from webium.controls.link import Link
from webium.controls.select import Select
from webium.find import Find, Finds


class Container(WebElement):
    second_element_with_id = Find(by=By.XPATH, value='.//*[2]')
    empty_element_list = Finds(by=By.XPATH, value='.//a[@no_such_attribute]')


class SpanContainer(object):
    span = Find(by=By.TAG_NAME, value='span')
    empty_element_list = Finds(by=By.XPATH, value='.//a[@no_such_attribute]')


class DivWithLink(WebElement):
    first_link = Find(Link, By.TAG_NAME, 'a')
    '''@type: Link'''


class SimplePage(BasePage):
    one_line = Find(by=By.ID, value='oneline')
    '''@type: WrongType'''
    icon_link = Find(Link, By.ID, 'validAnchorTag')
    checkbox = Find(Checkbox, By.ID, 'checkbox1')
    unexistent_element = Find(by=By.ID, value='no_such_id')
    physical_container = Find(Container, By.ID, 'div-with-pre')
    '''@type: Container'''
    default_search_type = Find(value='multiline')
github freenas / webui / tests / selenium / sys_general.py View on Github external
def test_01_nav_system_general(self):
        try:
           # Navigating to System>General page
            a = driver.find_element_by_xpath(xpaths['navSystem'])
            a.click()
            # allowing page to load by giving explicit time(in seconds)
            time.sleep(1)
            driver.find_element_by_xpath(xpaths['submenuGeneral']).click()
            # cancelling the tour
            if self.is_element_present(By.XPATH,'/html/body/div[6]/div[1]/button'):
                driver.find_element_by_xpath('/html/body/div[6]/div[1]/button').click()
            # get the ui element
            ui_element=driver.find_element_by_xpath('//*[@id="breadcrumb-bar"]/ul/li[2]/a')
            # get the weather data
            page_data=ui_element.text
            print ("the Page now is: " + page_data)
            # assert response
            self.assertTrue("General" in page_data)
            #taking screenshot
            function.screenshot(driver, self)
        except Exception:
            exc_info_p = traceback.format_exception(*sys.exc_info())
            #taking screenshot
            function.screenshot(driver, self)
            for i in range(1,len(exc_info_p)):
                print (exc_info_p[i].rstrip())
github venkywarriors619 / selenium_with_python / Python_basics / AutomationFramework_Part_3 / 177 4-selenium-driver.py View on Github external
def getByType(self, locatorType):
        locatorType = locatorType.lower()
        if locatorType == "id":
            return By.ID
        elif locatorType == "name":
            return By.NAME
        elif locatorType == "xpath":
            return By.XPATH
        elif locatorType == "css":
            return By.CSS_SELECTOR
        elif locatorType == "class":
            return By.CLASS_NAME
        elif locatorType == "link":
            return By.LINK_TEXT
        else:
            self.log.info("Locator type " + locatorType +
                          " not correct/supported")
        return False
github HDE / arsenic / src / arsenic / drivers / remote.py View on Github external
Note: The base path will be relative to this element's location.

        This will select the first link under this element.

        ::

            myelement.find_elements_by_xpath(".//a")

        However, this will select the first link on the page.

        ::

            myelement.find_elements_by_xpath("//a")

        """
        return await self.find_element(by=By.XPATH, value=xpath)
github zvovov / whatsapp-web / chat.py View on Github external
def getMsgMetaInfo(webdriver_element):
        """
        Returns webdriver_element's sender and message text.
        Message Text is a blank string, if it is a non-text message
        TODO: Identify msg type and print accordingly
        """
        # check for non-text message
        try:
            msg = webdriver_element.find_element(By.XPATH, './/div[contains(@class, "copyable-text")]')
            msg_sender = msg.get_attribute('data-pre-plain-text')
            msg_text = msg.find_elements(By.XPATH, './/span[contains(@class, "selectable-text")]')[-1].text
        except IndexError:
            msg_text = ""
        except Exception:
            msg_sender = ""
            msg_text = ""

        return msg_sender, msg_text
github jbms / finance-dl / finance_dl / amazon.py View on Github external
            lambda: self.find_visible_elements(By.XPATH, '//input[@type="email"]')
        )
github wolfmanstout / dragonfly-commands / _repeat.py View on Github external
"this bullets": Key("cs-8"),
    "this bold": Key("c-b"),
    "this link": Key("c-k"),
    "insert text box": Key("a-i/15, t"),
    "paste raw": Key("cs-v"),
    "match next": Key("c-g"),
    "match preev": Key("cs-g"),
    "bookmark open": Key("c-semicolon"),
    "tab [new] bookmark": Key("c-apostrophe"),
    "bookmark save": Key("c-d"),
    "frame next": Key("c-lbracket"),
    "developer tools": Key("cs-j"),
    "webdriver test": Function(webdriver.test_driver),
    "go search": webdriver.ClickElementAction(By.NAME, "q"),
    "bill new": webdriver.ClickElementAction(By.LINK_TEXT, "Add a bill"),
    "