Selenium is having trouble locating an element that should be clearly visible

My Java Selenium code needs to locate a visible element on the Google login API page. The HTML code is extracted from this page.

Below is the code snippet:


if(BaseSteps.elementExists(By.xpath("//*[@role=\"button\"]"), 30))
{
    System.out.println($(By.xpath("//*[@role=\"button\"]")));
    $(By.xpath("//*[@role=\"button\"]")).shouldBe(visible, ofSeconds(120)).click();
}

https://i.sstatic.net/yYuK7.png

The button in question has a display property set to inline-block as shown in the developer tools. The println() call outputs:

<div aria-disabled="false" class="U26fgb O0WRkf oG5Srb C0oVfc kHssdc M9Bg4d" data-custom-id="iPWQ6" data-id="ssJRIf" jsaction="click:cOuCgd; mousedown:UX7yZ; mouseup:lbsD7e; mouseenter:tfO1Yc; mouseleave:JywGue; focus:AHmuwe; blur:O22p3e; contextmenu:mg9Pef;touchstart:p6p2H; touchmove:FwuNnf; touchend:yfqBxc(preventMouseEvents=true|preventDefault=true); touchcancel:JMtRjd;" jscontroller="VXdfxd" jsname="LgbsSe" jsshadow role="button" tabindex="0" displayed:false></div>

At the end of the output, it states "displayed:false". I am unsure of its significance. Can someone help me identify the issue?

Answer №1

It appears the problem lies in the locator you are using not being unique.
The current locator is identifying 2 elements, with the first one being invisible and the second possibly visible. However, Selenium is clicking on the first element it finds, which is hidden from view.
This is why you are experiencing issues with clicking on it.
To resolve this, you will need to identify a unique locator for that specific element.

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

Centering navigation using HTML5

I've been struggling a bit trying to build a website, particularly with centering my <nav> tag. Despite reading numerous suggestions like using CSS properties such as margin: 0 auto; or text-align: center, nothing seems to be working for me. Si ...

Ways to resolve the issue of setAttribute value not appearing on the UI

When using the setAttribute method to set a value in the DOM, why is it not being displayed in the user interface? https://i.sstatic.net/hZRgX.png ...

Leveraging CSS Modules alongside external packages

Below is the important section from my webpack.config.js file: module: { loaders: [ { test: /\.css$/, exclude: /node_modules/, loaders: [ "style-loader?sourceMap", "css-l ...

How to extract date text using Selenium Webdriver

Using selenium webdriver, I am trying to extract text from a div tag containing a date. How can I achieve this? Below is the HTML snippet displaying the div tag: <div class="gridlayout-column" style="padding-left: 10px; width: calc((100% - 110px) * 0. ...

Why won't my Twitter Bootstrap navigation bar apply the styles?

I am currently working on a Rails app (4.0) and have incorporated Bootstrap 3 into my project. Both bootstrap.css and bootstrap-theme.css are stored in the stylesheets directory, while bootstrap.js is located in the javascripts directory. Most of the Boots ...

Creating a JAX-RS endpoint for handling POST requests with multiple parameters

Looking to create a JAX-RS web service using Jersey implementation? Need help with a post method that has 3 parameters? @POST @Path ("/addData") @produce(MediaType.Application_Json) @Consume(MediaType.Application_JSON) public User addData(int id, String n ...

Styling JavaScript strings with CSS - JavaScript/CSS Integration

I am trying to display a tooltip on hover using the data-tip attribute, but I am facing limitations with it only accepting strings. As a workaround, I have adopted the following approach: var title = "Hello World"; var online: "Last Online 2 mins ago". ...

How to customize tag option borders to blue with a blue background on hover in Chrome [Unable to find solution elsewhere]

Struggling to eliminate the blue border and blue background on hover from a select tag option. Despite searching for solutions, none seem to work as desired. Some codes helped change the background, but not what I intended to achieve. Any guidance would ...

What is the best way to transfer a string from one TestNG method to another?

During my tests, I encountered a challenge where I need to capture a string in one method and later utilize it in another method. The scenario is illustrated below: public class stackOverflowExample { public static WebDriver driver; public static Propert ...

Center alignment function is not functioning correctly

I'm struggling to center the text both vertically and horizontally inside my div. No matter what I try, I can only get it to align horizontally. Here is the CSS code I have been using: #loading > h1 { text-align: center; font-size: 21px; ani ...

Looking for assistance with aligning the "tape" image on top of another image

I'm attempting to overlay one image on top of another, in order to create the effect of a scrapbook with the images appearing as if they are "taped" onto the homepage. I want to maintain consistency with the tape layer while also allowing myself the ...

Is it possible to link a css file from an ascx control during registration?

Is there a specific way to register a css code block within an ascx control? Do I simply place <head id="head" runat="server"> <style type="text/css"> .customClass { background-color: Lime; } < ...

Make a diagonally slanted border for a cell

Is it feasible to create a table with diagonal borders using CSS or jQuery, similar to the one shown below? I would welcome any ideas on how this can be achieved. ...

My opinion is consistently disregarded

I'm currently troubleshooting my program and I've encountered an issue with saving items in an array. The problem is that the first input always seems to be ignored. For instance, when I ask the user if they want to enter more "xy," and they say ...

What is the best way to output my PHP code into separate div elements?

I am attempting to place the prints generated by this PHP code into separate HTML divs so that I can customize them using CSS. However, everything is currently being printed into a single div named "body" with the class "hasGoogleVoiceExt". <?php class ...

Achieve vertical center alignment of items using flexbox styling

I'm attempting to vertically center elements using CSS flexbox. I have successfully implemented it with the non-vendor-prefixed code, but I am facing issues in Webkit (Chrome) even with the vendor prefixes. My goal is to vertically align the spans wi ...

What is causing this image to expand when hovered over, even though it is not at 100% width in FF21?

I am experiencing an issue with a responsive image that has a hover transition. Everything works well when the image is at 100% width, but in Firefox version 21, when the browser window is resized causing the image to shrink and then hovering over it, ther ...

How can I make the background appear darker?

My website features a large background image, with the following code: body{ background-image: url(../images/front/bg.jpg); background-position: center center; background-size:cover; padding:0; margin:0; width:100%; height:100%; } I am looking to add a s ...

Tips for choosing the nth element from the image grid using selenium

Sample imageWhat is the best way to choose and click on the nth image in a grid? I attempted using the code below, however it does not seem to be working. List<WebElement> images = driver.findElements(By.cssSelector("img[class='course_icon&apo ...

Retrieving Every Row with Selenium

I have been attempting to retrieve all rows of data, but unfortunately I keep encountering errors. from selenium import webdriver import time url = "https://lobby.ogame.gameforge.com/" driver_path = "chromedriver.exe" browser = webd ...