• TechQA.

        Unable to trace an element by attribute or text

        92 views Asked by k.horde At 2015-06-11T13:34:48+00:00 11 June 2015 at 13:34 2025-12-24T01:00:23+00:00

        I am having trouble with clicking at an element of a menu which is written like this:

        <div class="menu">
        <ul class="tabs ctrlTabsProfile">
        <li class="active" data-tab="tabDetail">User Details</li>
        <li data-tab="tabEmail">Email</li>
        <li data-tab="tabPass">Change password</li>
        <li data-tab="tabAdress">Account Details</li>
        </ul>
        </div>
        

        I have tried these:

        driver.findElement(By.linkText("Account Details")).click();
        driver.findElement(By.cssSelector("li[data-tab=tabAdress")).click();
        driver.findElement(By.xpath("li[data-tab='tabAdress']")).click();
        

        also tried listing the elements but got null only :

        for(WebElement el : driver.findElements(By.cssSelector(".tabs.ctrlTabsProfile"))) {
        
                try {
                    assertTrue(driver.findElement(By.cssSelector("BODY")).getText().matches("^[\\s\\S]*Account Details[\\s\\S]*$"));
                } catch (Error e) {
                    System.out.println("Not found: \"Account Details\".");
                  }
        
            String s = el.getAttribute("data-tab");
            System.out.println(s);
            if(s.equals("tabAdress")) {
                driver.findElement(By.xpath("li[data-tab='tabAdress']")).click();
            }
           }
        

        Solutions? Sugestions? Errors?

        java testing selenium-webdriver webdriver
        Original Q&A
        2

        There are 2 answers

        1
        aholt aholt On 2015-06-11T14:33:10+00:00 11 June 2015 at 14:33 BEST ANSWER

        Well, for one, your xpath selector is incorrect.

        driver.findElement(By.xpath("li[data-tab='tabAdress']")).click();
        

        should be:

        driver.findElement(By.xpath("//li[@data-tab='tabAdress']")).click();
        

        edit:

        And your css selector is incorrect as well.

        driver.findElement(By.cssSelector("li[data-tab=tabAdress")).click();
        

        should be:

        driver.findElement(By.cssSelector("li[data-tab='tabAdress']")).click();
        

        edit #2:

        and:

        driver.findElement(By.linkText("Account Details")).click();
        

        will only work if the element is a link, which in this case it is not.

        1
        Aru Aru On 2015-06-11T20:55:06+00:00 11 June 2015 at 20:55

        Aholt is right, driver.findElements(By.cssSelector(".tabs.ctrlTabsProfile")) will return only ul elements. To access all <li>, you could try:

        driver.findElements(By.cssSelector("ul.tabs.ctrlTabsProfile li.active"))
        

        Related Questions in JAVA

        • I need the BIRT.war that is compatible with Java 17 and Tomcat 10
        • Creating global Class holder
        • No method found for class java.lang.String in Kafka
        • Issue edit a jtable with a pictures
        • getting error when trying to launch kotlin jar file that use supabase "java.lang.NoClassDefFoundError"
        • Does the && (logical AND) operator have a higher precedence than || (logical OR) operator in Java?
        • Mixed color rendering in a JTable
        • HTTPS configuration in Spring Boot, server returning timeout
        • How to use Layout to create textfields which dont increase in size?
        • Function for making the code wait in javafx
        • How to create beans of the same class for multiple template parameters in Spring
        • How could you print a specific String from an array with the values of an array from a double array on the same line, using iteration to print all?
        • org.telegram.telegrambots.meta.exceptions.TelegramApiException: Bot token and username can't be empty
        • Accessing Secret Variables in Classic Pipelines through Java app in Azure DevOps
        • Postgres && statement Error in Mybatis Mapper?

        Related Questions in TESTING

        • Using ES Modules with TS, and Jest testing(cannot use import statement outside module)
        • Mocking AmazonS3 listObjects function in scala
        • How to refer to the filepath of test data in test sourcecode?
        • No tests found for given includes: [com.bright.TwitterAnalog.AuthenticationControllerSpec.Register user with valid request](--tests filter)
        • Error WebMock::NetConnectNotAllowedError in testing with stub using minitest in rails (using Faraday)
        • How to use Mockito for WebClient get call?
        • Jest + JavaScript ES Modules
        • How to configure api http request with load testing
        • How can I make asserts on outbound HTTP requests?
        • higher coefficient of determination values in the testing phase compared to the training phase
        • Writing test methods with shared expensive set-up
        • Slow performance when testing non-local IP services with Playwright
        • uiState not updating in Tests
        • Incorrect implementation of calloc() introduces division by zero and how to detect it via testing?
        • How to test Creating and Cancelling Subscription in ThriveCart in Test Mode

        Related Questions in SELENIUM-WEBDRIVER

        • Selenium Python - The element I'm looking for cant be found even though it exists in Yahoo Finance
        • I am automating web scraping using python
        • Linkedin API for median tenure
        • How can I find a button element and click on it?
        • Scrolling Instagram Followers Not Working
        • Need Help Extracting Redirect URL from a div Element with Specific Class Name in Python Selenium
        • Selenium clicked button but still getting error and exiting
        • RSpec Capybara throwing Selenium error when trying to click a button with browser confirm
        • beautifulsoup library not showing below #document data inside iframe tag in python
        • Retreive a javascript variable from selenium (mutationobserver) to python
        • C# Error: 'ExtentReports' is a namespace but is used like a type
        • How to call Python function in JavaScript environment on Selenium?
        • Run automated tests in parallel on desktop and mobile browser
        • Optimizing Selenium script for faster execution
        • Parse Dynamic Power BI table with selenium

        Related Questions in WEBDRIVER

        • Getting NullPointerException when trying to use FindElements to read all elements
        • Not able to move a google maps map using move_to_element_with_offset() in selenium
        • How to resolve is_selected() not returning True even if the checkbox is selected?
        • Chrome window appears asking who was currently using Chrome
        • Code will run separately but not together for selenium webdriver
        • Selenium Google Login Block using webdriver options
        • Execute a function in js file referred in source of a html script by using Webdriver/Katalon commands
        • In Selenium, how to click on an element under HMTL under iframe. So the hierarchy from big to small: iframe>#document>HTML. I added the scrreenshot
        • JMeter WebDriver sampler Windows/Basic authentication
        • Unable to locate a precise webelement to be clickable in a list given by Selenium CSS Selector
        • Appium/WebdriverIo error appears when running test
        • Web Scraping With Selenium in a Docker Container
        • Why doesn't Selenium ActionChains work in a loop?
        • Bad parameter in WebDriver url causes cross-site request
        • How do I run Chrome through Appium (v2) on a windows machine ("No matching capabilities found")

        Popular Questions

        • How do I undo the most recent local commits in Git?
        • How can I remove a specific item from an array in JavaScript?
        • How do I delete a Git branch locally and remotely?
        • Find all files containing a specific text (string) on Linux?
        • How do I revert a Git repository to a previous commit?
        • How do I create an HTML button that acts like a link?
        • How do I check out a remote Git branch?
        • How do I force "git pull" to overwrite local files?
        • How do I list all files of a directory?
        • How to check whether a string contains a substring in JavaScript?
        • How do I redirect to another webpage?
        • How can I iterate over rows in a Pandas DataFrame?
        • How do I convert a String to an int in Java?
        • Does Python have a string 'contains' substring method?
        • How do I check if a string contains a specific word?

        Trending Questions

        • UIImageView Frame Doesn't Reflect Constraints
        • Is it possible to use adb commands to click on a view by finding its ID?
        • How to create a new web character symbol recognizable by html/javascript?
        • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
        • Heap Gives Page Fault
        • Connect ffmpeg to Visual Studio 2008
        • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
        • How to avoid default initialization of objects in std::vector?
        • second argument of the command line arguments in a format other than char** argv or char* argv[]
        • How to improve efficiency of algorithm which generates next lexicographic permutation?
        • Navigating to the another actvity app getting crash in android
        • How to read the particular message format in android and store in sqlite database?
        • Resetting inventory status after order is cancelled
        • Efficiently compute powers of X in SSE/AVX
        • Insert into an external database using ajax and php : POST 500 (Internal Server Error)
        • Privacy
        • Terms
        • Cookies
        • Homegardensmart
        • Math
        • Aftereffectstemplates