Logging in using Selenium WebDriver in Java

I'm just starting out with selenium webdriver and I need to automate a webpage for my project. Right now, I'm working on the login page but I'm having trouble with the login button. I'm not sure which locator to use for it. The login button code is as follows:

a href="javascript:LoginSubmit('Log In')">
img border="0" src="/opensso/login_images/button_enter.gif" 
alt="enter / entrez"

Can someone please assist me in using the above code with xPath or any other method related to JavaScript?

I apologize if I've overlooked something, since I'm still new to all of this.

Answer №1

It appears that in order to proceed, you should click on the Anchor(a) tag instead of the image. (Please note that this is based on my understanding without viewing the actual page.)

You could attempt using:

//a/img[@alt='enter / entrez']/..
or
//a/img[contains(@src,'button_enter.gif')]/..

The "/.." will bring you back to the anchor tag, similar to navigating to the parent directory in a command line interface.

Answer №2

Give this a shot:

driver.findElement(By.xpath("//a[contains(@href, 'javascript:LoginSubmit') and contains(@src, '/opensso/login_images/button_enter.gif')]")).click();

Alternatively,

driver.findElement(By.xpath("//img[contains(@alt, 'enter / entrez')]")).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 come the sound is played after the command is given?

function myTimer() { randint= Math.floor(Math.random() * 10)+1; randstimuli=gorilla.stimuliURL(dict[randint]); var audio = new Audio(randstimuli); audio.play(); var start=Date.now(); var ans=prompt("was the last number the same as t ...

Selenium WebDriver.get() experiences a delay when attempting to load a page that is empty and contains an alert popup for login

Recently, I encountered a page that requires testing with Selenium. It now uses an alert popup authentication system which has caused some issues. If you are unfamiliar with this setup, you can refer to this resource. My current approach closely aligns wi ...

Is there a way to generate random numbers that will create a chart with a general upward trend?

Are you looking for a solution to generate random numbers for charts that trend upwards and to the right? I am currently utilizing a JavaScript charting engine, so I will require numbers in JSON format eventually. However, I am open to alternative methods ...

Troubleshooting steps for resolving Heroku's "State changed from up to crashed" error caused by Mongoose connection issue

I am encountering an issue while deploying my Node.js/MongoDB app to Heroku. It crashes with the following error: MongooseServerSelectionError: connection <monitor> to 104.155.184.217:27017 closed Below are excerpts from my log: 2022-07-10T23:36:17. ...

Unable to view the refreshed DOM within the specifications after it has been altered

For my current project, I am working on writing a functional spec that involves using Mocha/JSDOM and making assertions with 'chai'. The specific use case I am tackling is related to the function called updateContent: When this function is exec ...

Are you conducting functional tests for Django on Travis?

Can Django Selenium tests be executed on Travis CI? Here are my test cases: class FrontendTest(unittest.TestCase): def setUp(self): self.browser = webdriver.Firefox() self.browser.implicitly_wait(3) def tearDown(self): se ...

Customizable form fields in AngularJS

Consider the scenario of the form below: First Name: string Last Name: string Married: checkbox % Display the following once the checkbox is selected % Partner First Name: Partner Last Name: [Submit] How can a form with optional fields be created in Angu ...

JS problem with decreasing

Within a React component, I have implemented the following method: addWidget = (index) => { let endX = this.state.widgets.reduce((endX, w) => endX.w + w.w, 0) console.log(endX); if (endX === 12) endX = 0 this.setState({ wi ...

The function fs.createReadStream does not exist

Snippet to Submit Career Form: import axios from 'axios'; import FormData from 'form-data'; var fs = require('fs'); submitCareerForm(e){ e.preventDefault(); let formData = new FormData(); //formdata obje ...

Encountered an issue with md-autocomplete: Attempting to read property 'success' of an undefined element

I encountered an issue while using Material Angular framework and md-autocomplete. The error message I receive is: Cannot read property 'success' of undefined. Below is the snippet of my code: /*My app.js*/ var app = angular.module('app&apo ...

Could a user upload a video directly to their channel using an HTML/JavaScript form?

Would it be feasible to enable a user to upload a video to their channel via an HTML/JavaScript form? If this is indeed possible, I am unsure of how the Google authentication process would function on the user's end. The code examples provided pertain ...

Express-Session Object Method

I am currently facing an issue with linking an object to an Express session. Below is the code I am using: var express = require('express'); var session = require('express-session'); // Defining an object named "engine" which simulate ...

After the Parent Component has successfully mounted, the Child Component will render

I am currently working with a third party library that has a unique prop allowing the user to pass in a string which is used to retrieve a DOM element and return its bottom value. <Sticky bottomBoundary="#some-id"> <MyChildComponentMightBeANa ...

Reading JSON documents in JavaScript through multiline strings

Having a JSON document with multiline string data is causing issues for me. I have attempted multiple options, but none of them have successfully solved the problem. For example: [ { "someString" : "A rather long string of English text, an error m ...

Optimal methods for organizing various perspectives on a one-page website

I am developing an application that incorporates AngularJS and Bootstrap. The current setup involves organizing various views using ng-show, allowing for view changes based on button interactions and the enablement/disabling of ng-show values. Within a si ...

Struggling to retrieve the Object from a JSON file located at a specific URL

Apologies if this comes across as naive, but my venture into javascript and json is just starting. I'm eager to access the JSON object from the twitter API after executing var myjson; $.getJSON('url of the Object', function(data) { ...

How to extract JSON data enclosed within HTML tags in Android application

My issue is slightly different than what I expected when I previously asked: Parse JSON to configure android application. I am receiving a JSON object from the server, and when I view it in the browser's source code, this is how it appears: JOSON.co ...

Simultaneously iterate through two recursive arrays (each containing another array) using JavaScript

I have two sets of arrays composed of objects, each of which may contain another set of arrays. How can I efficiently iterate through both arrays and compare them? interface items { name:string; subItems:items[]; value:string; } Array A=['parent1&ap ...

What is the best way to define the active <li> tab using JQuery?

Initially, my HTML code includes a set of <li> elements that I want to dynamically add to the existing <ul>. <ul class="tabs" id="modal_addquestion_ul"> <li class="tab-link current" data-tab="multipleChoice">Multiple Choice< ...

What is the process for constructing a regular expression (regex) in JavaScript to validate an id?

My validation requirements are relatively straightforward, but as someone who is new to regex, I am in need of quick assistance. The format should be either 1234567890 or 123456-7890, allowing for any number ranging from 0 to 9 and a total character length ...