• Re" />
    • Re" />
      • Re"/>

        TechQA.

        selenium webdriver to find the anchor tag and click that

        76k views Asked by Sathish Kumar k k At 2012-05-27T12:23:07+00:00 27 May 2012 at 12:23 2025-12-22T18:22:48+00:00
        <div id="ContentPrimary">
        <ul class="selectors modeSelectors">
            <li><a href="/content/l411846326l1213g/references/" title="">
                <span class="selector">References (27)</span></a></li>
            <li><a href="/content/l411846326l1213g/referrers/" title="">
                <span class="selector">Cited By (2)</span></a></li>
            <li><a href="/content/l411846326l1213g/export-citation/" title="">
                <span class="selector">Export Citation</span></a></li>
            <li><a href="/content/l411846326l1213g/about/" title="">
                <span class="selector">About</span></a></li>
        </ul>
        

        In this I need to find and click About link using Selenium api but I was unable to do it.

        what I did is

        wait.until(new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver webDriver) {
                System.out.println("Searching ...");
                String s = driver.findElement(By.cssSelector("#ContentPrimary ul li[4] span.selector")).getText();
                System.out.println(s);
                if (Pattern.compile(Pattern.quote("About"), Pattern.CASE_INSENSITIVE).matcher(s).find()) {
                    return true;
                } else {
                    return false;
                }
            }
        });
        driver.findElement(By.linkText("About")).click();
        

        but its not working

        java selenium web-scraping web-scripting
        Original Q&A
        3

        There are 3 answers

        4
        devsnd devsnd On 2012-05-27T12:34:18+00:00 27 May 2012 at 12:34 BEST ANSWER

        In my experience the Selenium API has many flaws in that way. They can mostly only be overcome by reformulating your selectors. For example you could try using a XPath selector to get your element:

        driver.findElement(By.xpath("//a[contains(.,'About')]")).click();
        

        Also, if you are trying to use the Internet Explorer it might help not to click the element, but instead to simulate pushing the Enter button. So assumung the Element is found, you could try this:

        driver.findElement(By.linkText("About")).sendKeys(Keys.ENTER);
        
        1
        Aleh Douhi Aleh Douhi On 2012-05-27T12:56:56+00:00 27 May 2012 at 12:56

        You can use ExpectedConditions:

        wait.until(visibilityOfElementLocated(By.linkText("About"))).click();
        
        0
        Thakhani Tharage Thakhani Tharage On 2023-04-26T04:59:57+00:00 26 April 2023 at 04:59

        Try using xpath to find the ancor then use that object to send an enter key

        anchorObj.sendKeys(Keys.ENTER);

        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 SELENIUM

        • Can't get Selenium element
        • Trying to find HREF from table with Selenium in Python
        • Python | How i get the link of products that doesn't have href with selenium
        • Selenium works only when I'm connected to a remote server
        • Logging in automation using Selenium requests / responses- why it wont work?
        • Why can't I scrape data from etherscan
        • TypeError: 'SwitchTo' object is not callable
        • Why driver.get doesn't work in Python Selenium when using Profile
        • Trying to fill out an online form using selenium but it can't find the element
        • Targeting Accept Policy With Selenium
        • Python Selenium - Select Options not returning all the options
        • Spraping data from a table is slow but uncertain why
        • Unable to convert byte[] image to base64 using cucumber scenario api's - java selenium
        • Selenium WebDriver - google account login problem using python
        • Click on login button using Selenium

        Related Questions in WEB-SCRAPING

        • Using Puppeteer to scrape a public API only when the data changes
        • Scraping information in a span located under nested span
        • How to scrape website which loads json content dynamically?
        • How can I find a button element and click on it?
        • WebScraping doesnt work, even without error
        • Need Help Extracting Redirect URL from a div Element with Specific Class Name in Python Selenium
        • beautifulsoup library not showing below #document data inside iframe tag in python
        • how to create robust scraper for specific website without updating code after develop?
        • Optimizing Selenium script for faster execution
        • Parse Dynamic Power BI table with selenium
        • How to extract table from webpage that requires click/toggle?
        • SSL Certificate Verification Error When Scraping Website and Inserting Data into MongoDB
        • Scraping all links using BeautifulSoup
        • How do I make it so all arrays are the same length?
        • I am getting 'NoneType object is not subscriptable' error in web scraping method

        Related Questions in WEB-SCRIPTING

        • IOT based queue management system with nodeMcu (esp8266)
        • Chrome script to append URL when specific pattern match
        • Python Selenium Dropdown list Clickable
        • Python Scrapy 999 error meaning. Linkedin company data scraping
        • issues with selenium, not finding by xpath on iframe
        • How to extract html input value by id with Selenium in Python
        • Element is found but not clickable
        • How to capture note screenshot from web page using typescript
        • How to check if the specific text on a website changed using python script
        • Grab information from inside the form using web scraping - python 3
        • When importing HTML into Google Sheets, there are issues with the order by and select col functions as well as the header
        • is it possible to receive Dom in google webscript?
        • Selenium Python: Invalid Selector in find_element_by_css_selector (Error)
        • Web scripting invalid syntax in URL
        • BeautifulSoup gives an empty list

        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
        • Aftereffectstemplates
        • Jogjafile