Web element not detected within Span Tag

Within my HTML, I have the following:

<span class="login-link">Log in</span>

The code snippet I am using is:

driver.findElement(By.cssSelector("#login > span")).click();

I have tried utilizing xPath, cssSelector, and id, but none of them seem to be working.

Would you be able to provide some assistance?

Answer №1

This xpath will help you locate the element:

driver.findElement(By.xpath("//span[text()='Log in']")).click();

Answer №2

To choose your element, you can also utilize the class selector method.

Give this a shot:

driver.findElement(By.cssSelector(".login-link")).click();

In CSS and JavaScript, the hash (#) is employed for referencing an id. To directly target the element, use a dot (.).

Answer №3

Based on the HTML shared and your code attempt, you have two options to locate the <span> tag:

  • cssSelector :

    driver.findElement(By.cssSelector("#login > span.login-link")).click();
    
  • xpath :

    driver.findElement(By.xpath("span[@class='login-link' and contains(.,'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

Creating a Parent Container to Maintain the Height of the Tallest Offspring

I've been searching online for solutions, but so far I haven't found one that meets all the requirements. <div class="parent"> <div class="child1">I am 60px tall and always visible; my parent is 100px tall</div> <div ...

Is there a way to construct a project using JNI without the header being regenerated during the building process?

I found a helpful tutorial on JNI in Eclipse that I'm using: (Specifically following section "2.6 JNI in Eclipse"). The example provided in the tutorial (HelloJNI) worked successfully for me and my project. After making a change to the header file ...

Limited to single sign-on using Selenium and Django testing

While experimenting with Django's tests and Selenium, I encountered an issue where I am unable to log in more than once using a live browser. I am utilizing Django's StaticLiveServerTestCase to interact with static and media files in real-time. M ...

Achieving consistent sizing for React-Bootstrap cards: A guide

In my React app, I am utilizing React-bootstrap and specifically the Card & CardGroup components. I need assistance in ensuring that all the cards have the same height. JSX component: <Card style={{flex: 1}} className="card"> ...

Getting the css property scaleX with JQuery is as simple as executing the

I am struggling to print out the properties of a specific div element using jQuery. My goal is to have the different css properties displayed in an information panel on the screen. Currently, I am facing difficulties trying to show scaleX. Here is my curr ...

Tips for preventing elements from wrapping in a lengthy list and using scrollbars in Firefox

When dealing with a lengthy flex list, the items (buttons) should wrap when there is not enough space available (using flex-wrap). However, an issue arises in Firefox where the items are wrapped once a scrollbar appears, even if there is ample space. In c ...

Can PowerMock be used to apply partial mocking to private static methods?

After browsing the examples on the PowerMock homepage, I came across a method for partially mocking a private method with Mockito: @RunWith(PowerMockRunner.class) // We prepare PartialMockClass for test because it's final or we need to mock private o ...

Guide to transforming a JSON file value into a JavaScript list

I need assistance with converting a string of comma-separated values in a JSON file into a list. The goal is to iterate through the list in a for loop and click on each element. Can you help me with this task? testdata.json : {"optionsList":&quo ...

Having trouble parsing Dynamic Key-Value pair JSON with a Custom JsonDeserializer in GSON?

I have been trying to parse JSON using a custom deserializer for nesting objects. Below is the code for my deserializer: class MapDeserializer implements JsonDeserializer<Map<String, String>> { public Map<String, String> deser ...

Selecting multiple items from a grid using the Ionic framework

I am looking to create a grid of category images in Ionic framework, where users can select multiple categories and send their values to the controller. However, I'm unsure about how to make this happen with Ionic framework. Below is the view I curre ...

Can Bootstrap be used to display a customized navbar on specific devices, while showing a different navbar on smaller screens?

Hello everyone, I have a quick and specific question. Currently, I have created a custom navbar (see image below). However, I want this navbar to be deactivated when the screen size is too small and instead show a regular navbar at the top. Is it achievabl ...

There are no additional intents set after the onBackPressed event

Update: Everything functions perfectly when the Android back button (the default one at the bottom of the screen) is pressed. However, I am encountering an issue with the menu back button... I am attempting to transmit the following intents from my Custom ...

Is there a way to use Selenium to scroll down within a scrollable panel and not the entire window?

My goal was to extract the names and usage data of Pokémon from the left-side panel on . Using BeautifulSoup for web scraping, I encountered a limitation - it could only scrape the first 25 data entries due to the source code not being fully expanded. Thi ...

VBA automation is unable to retrieve innerText (or innerHTML, value)

I've encountered a problem with getting innertext this time. Despite trying various alternatives, I have not been successful. Firstly, I am using Selenium on VBA with chromedriver. The source website is "[" This website operates within an Iframe. Aft ...

Pull content to the left using the pull-xs-left helper classes in Bootstrap 4

Is it supposed to work in theory? I'm attempting to float this box to the right on a row with 3 columns. What am I doing incorrectly here? Here is a pen: https://codepen.io/lucky500/pen/JbMMby <div class="container"> <div class="row"> ...

Is there a way to limit the height of the tbody element?

I need to set a max-height rule for a table's tbody with overflow set to auto, so that a scrollbar only appears when the table exceeds a certain height. Is there a way to restrict the height of a tbody element within a table in this manner? The tabl ...

Need help resolving an issue with an HTML header that's overlapping in JavaScript?

Hey there! I was working on implementing a dynamic header that resizes as you scroll on the page. I also decided to try out Headroom as an additional solution, and it seems to be functioning well in terms of hiding the header. You can check out my progress ...

When using Internet Explorer 9 or a virtual machine, Selenium tests may not run if the browser window or virtual machine is

In the scenario below, there seems to be an issue with running a login test on Internet Explorer version 9 using Selenium 2.42.2 in Java: InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS=true InternetExplorerDriver.IGNORE_ZOOM_SETTI ...

Atomic updating of a MongoDB collection if the set does not already exist

In my collection, I have a document with the following details: { "_id":NumberLong(106379), "_class":"x.y.z.SomeObject", "name":"Some Name", "information":{ "hotelId":NumberLong(106379), "names":[ { "localeStr" ...

Leveraging JsonPath to retrieve data without prior knowledge of the key

I have a Json string that looks like the following: "files": { "fileA.c": { "size": 100 }, "fileB.txt": { "size": 200 } } My goal is to extract the names of the files, {"fileA.c","fileB.txt"}, using JsonPath. It& ...