Skip to content

element not found using XPath #612

@jbnjohnathan

Description

@jbnjohnathan

I am trying to click on a drop down box created in React in order to select an item in it

This is my SeleniumBase code which is not working (running with pytest --browser=firefox)

from seleniumbase import BaseCase
class MyTestClass(BaseCase):
    def test_ant_dropdown(self):
        url = "https://ant.design/components/select/"
        self.open(url)
        self.assert_title("Select - Ant Design")
        self.click('//*[@id="rc_select_13"]')

Error message is

exception = <class 'selenium.common.exceptions.ElementNotVisibleException'>
message = '\n Element {//*[@id="rc_select_13"]} was not visible after 6 seconds!'

Trying the same with Selenium Webdriver (this works)

# Generated by Selenium IDE
import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities


class TestAdddevice:
    def setup_method(self, method):
        # self.driver = webdriver.Firefox()
        self.driver = webdriver.Firefox(
            executable_path=r"/usr/local/lib/python3.7/dist-packages/seleniumbase-1.42.4-py3.7.egg/seleniumbase/drivers/geckodriver"
        )
        self.vars = {}

    def teardown_method(self, method):
        self.driver.quit()

    def test_adddevice(self):
        self.driver.get("https://ant.design/components/select/")
        self.driver.find_element(By.XPATH, "//*[@id='rc_select_13']").click()

This works.
The XPATH is exactly the same, but for some reason SeleniumBase cannot click it.

As I workaround I use this code which works

from seleniumbase import BaseCase
from selenium.webdriver.common.by import By
class MyTestClass(BaseCase):
    def test_ant_dropdown(self):
        url = "https://ant.design/components/select/"
        self.open(url)
        self.assert_title("Select - Ant Design")
        self.driver.find_element(By.XPATH, "//*[@id='rc_select_13']").click()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions