Activating an image button with Selenium WebDriver post login

I'm facing an issue while automating a login page with selenium-webdriver using IE as the browser. The problem arises after logging in, where I am unable to select the image button. Despite adding time delays and trying various methods, the script runs without clicking the button. I have commented out all the attempted solutions.

The code snippet I utilized is:

    System.setProperty("webdriver.ie.driver",
            "C:/Program Files/IEDriverServer/IEDriverServer.exe");

    WebDriver driver=new InternetExplorerDriver();
    driver.manage().window().maximize();

    driver.navigate().to("website name");

    driver.findElement(By.id("userid")).sendKeys("username");
    driver.findElement(By.id("password")).sendKeys("password");
    //driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
    driver.findElement(By.id("submitButton")).click();
    Thread.sleep(5000);
    //driver.findElement(By.id("imgBtnAdd")).click();
    //driver.findElement(By.cssSelector("a[href='Images/Go.gif']")).click(); 
    driver.findElement(By.xpath("//img[@ src='Images/Go.gif']")).click();
    //System.out.println("Manual Click of Ok button");
    //By xpath = By.xpath("//button[@name='imgBtnAdd'][@type='image'][contains(image(),'Images/Go.gif')]");
    //WebElement myDynamicElement = (new WebDriverWait(driver, 10))
      //.until(ExpectedConditions.presenceOfElementLocated(xpath));
    //myDynamicElement.click();

    driver.findElement(By.cssSelector("input[id='rblRoleGroup_4']")).click();

    driver.findElement(By.id("imgBtnRoleGroup")).click();

    //WebElement element = driver.findElement(By.id("imgBtnAdd"));
    //Thread.sleep(5000);
    //JavascriptExecutor executor = (JavascriptExecutor)driver;
    //executor.executeScript("arguments[0].click();", element);        
    //driver.close();

Answer №1

Here are some suggested solutions:

To simulate pressing the Enter key, you can use sendKeys method:
driver.findElement(By.id("imgBtnAdd")).sendKeys(Keys.ENTER);

If the image is in a new window, you can switch to that window using this code snippet:

for(String winHandle : driver.getWindowHandles())

{

driver.switchTo().window(winHandle);

}

Answer №2

You could potentially improve your click functionality by utilizing the JavascriptExecuter in your code snippet:

      WebElement element =  driver.findElement(By.id("imgBtnAdd"));

      JavascriptExecutor js = (JavascriptExecutor)driver;
      js.executeScript("arguments[0].click();", element);

Answer №3

Upon reviewing your code, it is evident that there was an error in your xpath.

Instead of utilizing the <img> tag, try switching to the <input> tag.

driver.findElement(By.xpath("//input[@src='Images/Go.gif']")).click();

Explanation for xpath:- Make use of the src attribute found within the <input> tag.

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

When using Jquery, input can be appended on the last child element when a key

I am new to JavaScript and want to enhance my page's functionality using jQuery. Here is my current HTML: <div class="input_fields_wrap"> <div><ul class="inputList"></ul></div> </div> My goal ...

Retrieve the nearest identifier text from the tables

I have a table on my webpage with some data: <tbody id="carga"> <tr> <td>1</td> <td id="nombre">esteban</td> <td id="apellido">aguirre</td> <td>N/A</td> <td>N/A</td ...

Leveraging the Selenium IE driver with C# to efficiently publish a substantial volume of text consisting of 10,000 lines

Currently, I am working on a script to automate a repetitive task using the Selenium Internet Explorer driver in C#. Everything is running smoothly, but there is a slight delay during one particular part of the script. I am exploring if there is a faster w ...

Sorting elements in an array using jQuery is a common task that can be easily accomplished

Query: I am faced with a challenge in handling a table where rows are dynamically added upon button clicks. To allow users to rearrange the rows, I have incorporated the jquery-ui sortable() function for sorting purposes. Consider the following scenario: ...

The MongoDB repository's save() method performs an insert operation rather than an update

Currently, I am working on developing a PUT request API using Spring and MongoDB. However, I have encountered an issue where the save() method is inserting a new object instead of updating the existing one. @Document("Test") public class Expense ...

Utilizing AngularJS ng-repeat to dynamically assign distinct values to buttons; techniques for extracting the assigned value to JavaScript upon button click

In my Angular project, I am creating a waiting list system where users can join a waiting list and then be moved to a member list. To populate the table with rows of waiting people, I am using ng-repeat. Each row has a button that, when clicked, should mov ...

The peculiar characteristics of the dragLeave event in various web browsers

I observed a peculiar behavior while working with drag events in Internet Explorer 11. It seems that adding a 'width' property to the elements triggers the dragLeave event, whereas without it, the event does not fire. Can anyone shed light on why ...

When using Vue to bind a data URI to the img src property, I noticed that the image in the browser only updates when there is

Currently, I am working on generating a base64 string to represent an image and passing that image data to a child component as part of an object property. The object class I am using for this purpose has an image property along with some other properties ...

Attempting to extract JavaScript URLs using scraping methods, however, receiving an empty string when utilizing

I need help accessing and extracting data from a URL that is embedded within a specific tag. The tag in question looks like this: <script src="http://includes.mpt-static.com/data/7CE5047496" type="text/javascript" charset="utf-8"></script> S ...

Identifying periods of inactivity using an embedded iframe

I have developed a website that showcases a three.js model within an iframe. My goal is to redirect users back to the homepage (index.html) after they have been inactive for a specified amount of time. While I have managed to achieve this using JavaScript, ...

Trying to match an individual variable with every single value in a list

I recently created a script for a Google Sheet that involves taking user input and comparing it to values already on the spreadsheet. Within the function below, I captured the user's desired number using the variable voltReqed. My goal is to compare ...

"Utilizing JSON parsing in Node.js and rendering the data in a Jade template

I need assistance with parsing JSON and presenting the response in a tabular format using Jade. Can you help me display the key-value pairs in two separate columns? Node.js exports.postMQinput = function(req, res) { req.assert('name', 'Q ...

Identifying the key with a null value

I have a situation where I am iterating through an array to verify if the values of calendar and tpoint are set. Within the if-statement, in the else block, I am trying to extract the name of the key using var notSelected = (obj.prop.subProp).val() !== &ap ...

How to Determine the Length of a Subarray in JavaScript

I am working with a JSON element that contains nested arrays: json = [ { "category": "Electronic", "param": "param1", "subMenu": [ { "subCategory": "Audio & Hifi", ...

Compare the versions of React used in the linked library and the workspace application

As I work on developing a React library containing my commonly used components, I have organized my project structure in the following way: In the root folder, there is my rollup config file and the src/ folder which houses my library. Upon building, the ...

When utilizing jQuery in HTML, the Marquee will bounce back upon reaching the end

My issue is that when I use a regular marquee, the text simply goes to the end and does not bounce back to the start as soon as it reaches the end of the div. Instead of using a normal marquee, I am looking to achieve this desired effect by utilizing jQue ...

Polymer encountered styling limitations when trying to apply custom styles to a repeated template tag

When attempting to style the paper-button inside the template, I have tested various approaches and only one has worked. How can I correctly apply styling? In my index.html file, I am calling the iron-ajax element and on the last-response, I'm invokin ...

A guide on incorporating a component from a nested directory with webpack

https://i.sstatic.net/kLB0S.png The directory structure above shows how my react app 'MyProject' is organized. Using this structure, I successfully utilize the Layout component in Main.jsx (located at src/Main.jsx) by : import Layout from &apo ...

Tips for testing a mapbox popup using jasmine testing?

I encountered an issue with my mapbox popup while using jasmine and attempting to write a unit test for it. Here is the function in question: selectCluster(event: MouseEvent, feature: any) { event.stopPropagation(); this.selectedCluster = {geo ...

Error encountered: AXIOS request failed due to XSRF-TOKEN Mismatch

My server is receiving different X-XSRF-TOKEN headers compared to the cookies being sent when I make requests 2-3 times per second using axios. let axiosInstance = axios.create({ baseUrl: "MY_BASE_URL_HERE", timeout: 20000 } ...