Is there a way in Selenium to determine the type of tag associated with the element we are trying to locate?

Is there a way in Selenium to determine the type of tag? On my automation page, some fields may change their type. For example, if the first field value is greater, the second field becomes an input text; if the first is "IN", then a dropdown appears. So, is there a method using JavaScript executor to find the tag name from the identified element?

I have tried the following 2 methods:

WebElement ele = driver.findElement(By.id("identifierId"));
String tag = (String) ((JavascriptExecutor) driver).executeScript("return ele.tagName");
System.out.println(tag);

2) Using XPath:

String xpath = "input[id='identifierId']";
String mainURL = (String) ((JavascriptExecutor) driver).executeScript("return (document.querySelector(\"xpath \").tagName)");

Is there a solution for this?

Answer №1

If you're using Java, this snippet of code will return the tag name for you.

driver.findElement(By.id("username")).getTagName()

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

Switching between three div elements along with two icons can be done by using toggle functionality

Is there a way to make the icon change back when clicked again without making major changes to the existing code? Looking for suggestions on how to achieve this functionality. function myFunction() { var element = document.getElementById("demo"); el ...

Guide to developing a reusable component or partial in react.js

My first experience with React.js involved a relatively simple task. I started by creating an app.js file that loads the initial page, containing my navigation menu and rendering the children props. However, I realized that instead of keeping the navigat ...

Using Selenium in Python to effectively capture and analyze network traffic responses

I'm encountering a problem where I can't seem to access the network traffic responses in Firefox using Selenium (Python). While solutions are available for the Chrome webdriver, my specific requirement is to work with the Firefox version. Despite ...

Show a mpld3 graph in an HTML page using the Django framework

Incorporating mpld3 to showcase matplotlib charts within an HTML page through django has been my recent focus. I utilize the mpld3.fig_to_dict method to convert a matplotlib figure into a JSON string and store it in a variable. However, I am encountering ...

Is the Ajax response value consistently 1?

I am facing an issue where a JavaScript in an HTML page is sending two variables to a PHP script, which then echoes one of the variables at the end. However, the response value always remains 1. Despite trying methods like alerting, console.log, and puttin ...

What is the best way to embed a variable within a Directive HTML block for seamless access by the Controller?

I am facing a challenge with my custom directive that inserts an HTML block onto the page. The issue is to have a variable within this block that can be manipulated based on an ng-click function in my controller. This is what my directive looks like: .di ...

JavaScript and jQuery are lightning fast, especially when the page is reloaded

I am currently working on a responsive website that uses liquid layouts. I have encountered challenges when incorporating images in the design, especially when dealing with different browsers like IE, Firefox, and Chrome. Recently, I faced another issue w ...

Exploring the variations between getRequestHandler and render functions in Custom Next.js applicationsIn a

Greetings, I found it quite unexpected that there is a lack of information available on the functionalities of the getRequestHandler and render functions within the next package. As I am in the process of setting up a custom server, I am curious about wh ...

What is the reason for the emergence of this error message: "TypeError: mkdirp is not recognized as a function"?

While running the code, I encountered an error indicating that the file creation process was not working. I am seeking assistance to resolve this issue. The code is designed to fetch data from the Naver Trend API and Naver Advertising API, calculate resul ...

Is it possible for me to pass a value through props that is not currently stored in the state?

Within the realm of Reactjs, imagine a scenario where there exists a <Parent> component containing state and a variable named foo, which is either 'global' or local to Parent. The question arises: Can we pass foo as props using <Child v ...

Issue with watir webdriver script not running successfully in Jenkins platform

I recently set up Jenkins on my local machine and now I want to run a watir webdriver script in Jenkins that is currently running successfully through the command prompt. Below is the basic watir script: require 'watir-webdriver' b=Watir::Browse ...

unable to utilize the library three.js

I stumbled upon an interesting animation on Codepen that uses blocks to reconstruct a map image. The necessary JavaScript files are three.min.js and TweenMax.min.js. I copied the links from Codepen and pasted them into my HTML using <script src="">&l ...

Enhance the original array of a recursive treeview in VueJS

After going through this tutorial, I decided to create my own tree view using recursive components in Vue.js. The structure of the input array is as follows: let tree = { label: 'root', nodes: [ { label: 'item1', nod ...

org.openqa.selenium.InvalidSelectorException: The element cannot be found using the xpath expression provided by con_reader.getusermobile()

While implementing the object repository in a base class using the page object model, I encountered an issue where Selenium was unable to identify the element and returned an invalid selector exception. Below are the classes I executed: Package Failed_S ...

Using an array.map inside a stateless component with React.createElement: the type provided is invalid

There is a component called BasicDetail in my code with the following structure: import React from "react"; import { Grid, Form } from "semantic-ui-react"; const BasicDetail = ({DetailData}) => { return( <div> <Grid.Ro ...

Passing a variable between functions in JavaScript: Tips and tricks

let chart; let data = new Array(); function handleClick() { data = document.getElementById('graph:hi').value; alert(data); } let chartData = new Array(66, 15, 2.5, 21.9, 25.2, 23.0, 22.6, 21.2, 19.3, 16.6, 14.8); alert(chartData); jQuery ...

The method of implementing an index signature within TypeScript

I'm currently tackling the challenge of using reduce in Typescript to calculate the total count of incoming messages. My struggle lies in understanding how to incorporate an index signature into my code. The error message that keeps popping up states: ...

Determining the successful completion of an ajax request using jQuery editable plugin

I recently started using Jeditable to enable inline editing on my website. $(".video_content_right .project_description").editable(BASE_URL+"/update/description", { indicator: "<img src='" + BASE_URL + "/resources/assets/front/images/indicator ...

Undefined property error

router.post('/:token',(req,res)=>{ let language= req.query.language let name= req.query.name let param =[] if(req.path.length == 5){ param.push({ language: language },{ name: name }) ddp.personConnected(param, function(err, response) { i ...

Tips for getting rid of Next.js' default loading indicator

While working on my project using Next.js, I've noticed that whenever I change the route, a default loading indicator appears in the corner of the screen. https://i.sstatic.net/FVWEU.gif Does anyone know how to remove this default loading indicator ...