Having trouble locating the element using xpath for selection purposes

Hey, I'm encountering a major challenge while trying to find this element using xpath:

class="accountSettingsTextBase_1u09j40-o_O-accountSettingsItemText_10y8axf" aria-current="false" href="/account/signin">Log In

I've experimented with:

"//*[contains(text(),'Log In')]"

and also the specific xpath:

//*[@id='root']/div/header/div[3]/nav/ul/li[1]/a

even attempting link text, but it's still not functioning. Any thoughts?

Just so you know, the anchor tags are absent from the HTML, as it only displayed "Log In" when they were included.

For the complete HTML: Full HTML

Answer №1

Possible ways to locate elements :

//a[@href='/account/signin']

OR

//a[contains(.,'Log In')]

OR

Consider using Css selector :

a[class^='accountSettingsTextBase_' ][class*='accountSettingsItemText']

Answer №2

//[contains(text(),'Sign In')]

Looks like you need to add this:

//*[contains(text(),'Sign In')]

Answer №3

Is there a reason you are not utilizing

driver.findElement(By.linkText("Log In"))

or possibly

driver.findElement(By.partialLinkText("Log In"))

considering the fact that the element happens to be an anchor tag?

Answer №4

Make sure to include an explicit wait before verifying the presence

Include the following code snippet for implementing an explicit wait:
WebDriverWait wait=new WebDriverWait(driver,20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[contains(text(),'Log In')]")));
driver.findElement(By.xpath("//*[contains(text(),'Log In')]")).click();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I extract the specific text within a <div> tag using Selenium and Python in an Angular website?

Seeking to extract the exact text enclosed within a tag using selenium with Python. Upon inspecting the element, the following HTML code is visible on the browser: <div class="value ng-binding" ng-bind="currentEarning">£8.8</div> == $0 A Py ...

Updating the row by substituting the content of two columns with the data retrieved from the action class

In my JSP page, there is a table with a refresh button on each row. Upon clicking the refresh button, a JavaScript/AJAX call is made to an action class to retrieve the values of status and number of records for that row, which are then displayed in the cor ...

The Selenium test case script using JUnit is malfunctioning on Eclipse when attempting to run it with the Firefox driver

I have attempted to run my program using various versions of Firefox (45, 48, 49, and 50) with no success. I have also specified the path for the Gecko driver (64 bit) within my code, but unfortunately, the Firefox browser fails to open when I execute the ...

Comparing the Efficiency of Caching JSON Strings and Java Objects

One of the strategies I use in my web services is caching the result with memcached. I have two options for caching: either cache the resulting JSON or cache the source object. However, when caching the source object, I need to convert it to JSON every t ...

Ways to interact with a button that toggles between states

I am working with a button that has both an enabled and disabled state. Enabled State: <button type="button" class="btt-download-csv site-toolbar-menu-button icon-download no-icon-margins ng-isolate-scope" title="Download CSV" rc-download-csv="" curren ...

Retrieve the ReadTimeout while using Selenium webdrivers on Heroku platform

Encountering an error while using selenium webdrivers on Heroku. (rspec->capybara->selenium) Net::ReadTimeout: Net::ReadTimeout with #<TCPSocket:(closed)> Utilizing the heroku-buildpack-google-chrome buildpack, alongside webdrivers-gem. Here is th ...

Guide on inserting websites into the compatibility view list with the use of any webdriver in Internet Explorer 11

Webdrivers like Selenium and Microsoft webdrivers for IE allow developers to use APIs to manipulate web pages by minimizing or maximizing browser windows. Is there a webdriver API available that can add or modify websites in the compatibility view list by ...

Capturing Screenshots as Numpy Arrays Using Selenium WebDriver in Python

Can selenium webdriver capture a screenshot and transform it into a numpy array without saving it? I plan to use it with openCV. Please keep in mind that I'm looking for a solution that avoids saving the image separately before using it. ...

Is it possible to run both a Spring Boot JAR and Next.js app on the same port within a packaged JAR

Is it possible to run NextJs code on a different port like 3000, and have it combined with Springboot in an executable Jar/WAR (with embedded Tomcat) running on default port 8080? Can the combined application jar/war be configured to run on a single port? ...

Extract information from a webpage using Selenium WebDriver

Currently, I am working on mastering Selenium, but I have hit a roadblock that I need assistance with. My task is to gather all the betting information for games from the following link and store it into an array. Given my limited experience with HTML an ...

Contrasting the uses of element(...) versus element(...).getWebElement() in Protractor

What is the advantage of using element(...).getWebElement() instead of element(...) when they both perform similarly? Why are there two different APIs for the same purpose? ...

Tips for extracting YouTube video descriptions using Beautiful Soup

I've been attempting to scrape a list of YouTube videos and extract their descriptions but have been unsuccessful so far. Any guidance on why this may be happening would be greatly appreciated. (Here is the YouTube video in question: https://www.youtu ...

Tests pass successfully on local environment, but encounter failures on Circle CI

I've encountered an issue with my ActiveAdmin view while running feature specs on CircleCi. It works perfectly fine on my local machine, but fails with the error message: undefined method `text' for nil:NilClass spec it 'utilizes the upd ...

Executing tests with Selenium webdriver when the browser is minimized can be done by adjusting the browser window

I encountered an issue while running this program. It performs well with codes initially, but when I tried to minimize the browser, an error popped up indicating that the program couldn't find the button. Is there a solution available to address this ...

Guide on pressing the "Next" button on the Twitter login page with Selenium and Python

Currently, I am working on developing a Twitter automation bot using Selenium. However, I have encountered an error when attempting to log in and click on the next button after entering the user ID. I have experimented with various methods like xpath, lin ...

What is the best way to customize the appearance of a non-current month cell within the date picker?

I'm currently in the process of developing a registration form for my JavaFX application. I am faced with an issue where I need to disable certain cells in the date picker when they do not belong to the displayed month. Let's take a look at my cu ...

Tips on how to incorporate information into variables in cucumber's feature files?

Currently tackling a UI selenium project where the goal is to extract String data from the UI and convert it into a variable within my .feature scenario file. In order to illustrate, let's take an example where I only have access to the customerID: ...

Is it possible to extract data from tables that have the 'ngcontent' structure using Selenium with Python?

Scraping basic tables with Selenium is a simple task. However, I've been encountering difficulties when trying to scrape tables that contain "_ngcontent" notations (as seen at "https://material.angular.io/components/table/overview"). My goal is to con ...

Retrieving the innerHTML or innerText of a structural DOM element generated by *ngFor in Selenium

Having trouble accessing the innerHTML/innerText of a structural DOM element, only getting a commented element instead of the child elements. <div class="snap-box"> <label class="snap-heading">Recommendations</label> <div class="r ...

Capture the content of the currently selected cell, launch a web browser, enter the captured content into the search field, and retrieve the URL of the resulting webpage

I want to achieve the following: Retrieve the value of an active cell (a property address) Launch Edge using a Selenium Edge Driver to go to www.redfin.com Search for the value from the cell (the property address) Capture the URL from the search re ...