Running a Javascript command in Selenium to extract information from a website

    <h4>Lotus</h4>

My goal is to extract the value of Lotus from the h4 tag. In a previous post, I found a solution using a JavaScript command:

document.getElementById('17285').getElementsByTagName('h4')[0].innerHTML;

This worked perfectly for me.

Now, I want to implement this JavaScript code in Selenium.

I attempted the following code:

MsgBox driver.executeScript("javascript:document.getElementById('17285').getElementsByTagName('h4')[0].innerHTML;")

However, I am getting an empty message box. Can anyone help me understand why?

Thank you in advance for your assistance!

Answer №1

The ID specified in the HTML (17171) does not align with the ID in the code (17285). Please use the following script:

MsgBox driver.executeScript("javascript:document.getElementById('17171').getElementsByTagName('h4')[0].innerHTML;")

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

What is the best way to interpret JSON using JavaScript?

Do you know how to access and read JSON in JavaScript? Here is an example of a JSON string: {"person":{"First name":"Dharmalingm","Last name":"Arumugam","Address":{"door number":"123","street":"sample street","city":"sample_city"},"phone number":{"mobile ...

What is the method to identify the key responsible for triggering a textbox input event?

Suppose there is a textbox on the webpage: <input id='Sub' type='text'> To capture each time the input changes, you can use the following code: sub = document.getElementById('Sub'); sub.addEventListener('input&a ...

Anomaly in Express route regular expressions

I have a question that may seem silly, but I'm struggling to figure it out. I want to match any route that doesn't contain a specific word, like "api" (excluding /api/*), but I can't seem to make it work: '/^(?=\/).(?!api\/). ...

How can I automatically bind a collection from an HTML form using the node.js express framework?

Is there a way to bind collections on the server side? For instance: Single Binding <input type="text" name="person[name]" /> This binds to: person:{ name: 'Name from HTML form' } If using Express, you can access this object at: a ...

Unable to display elements from an array in the dropdown menu generated by v-for

Having just started learning Vue.js, I am facing a challenge in rendering the following array: countries: ["US", "UK", "EU" ] I want to display this array in a select menu: <select> <option disabled value="">Your Country</option& ...

What is the reason that the function variable doesn't display the entire function body when logged in the console?

Can you explain why the function variable, when logged in the console, does not display the entire function body but the toString() method does? function person(name) { this.f_name = name; return function print_name (){ alert("Your ...

Is there a way to bypass the remaining tests in the class if one has already failed?

Currently, I am developing test cases for web testing using a combination of Jenkins, Python, Selenium2 (webdriver), and Py.test frameworks. I have structured my tests in the following way: each Class represents a Test Case and each `test_` method serves ...

Using JavaScript to convert date and time into ISO format

Similar Question: How do I output an ISO-8601 formatted string in Javascript? I've been attempting to change a date and time input into an ISO format but keep encountering the error .toISOString is undefined. It seems like I must be overlooking s ...

The display of options in React Bootstrap typeahead is not functioning properly

When I try to implement React Bootstrap Typeahead, the options do not appear in the Typeahead component upon page load. Here is a snippet of my code: const React = require('react'); ... (code continues) The options are generated as follows: [ ...

Access a file from an npm module using an executable command

I have a npm module called @jcubic/lips, which includes an executable file. I need to open a file located within the module's directory. This module is installed globally. The specific file I want to access is ../examples/helpers.lips, relative to th ...

Tips for redirecting a page in React by forcing a route

Attempting to implement the guidance from this Stack Overflow solution on how to "go back home" after closing a Modal... import React, { Suspense, useState } from 'react'; import { BrowserRouter, Route, Switch, useHistory } from "react-route ...

Identify a request in NodeJS without relying on express or accessing the request object independently of an express middleware

I am struggling with accessing the request object outside of an express middleware in NodeJS. In my code snippet below, I need to read the request object from a file called mongoose_models.js, where I don't have access to the express middleware argume ...

Enhancing User Experience with Animated jQuery Progress Bar

I came across a cool tutorial on animating progress bars: The only issue was that the progress bar didn't utilize jquery, and there wasn't information on linking multiple buttons to it. After some searching, I found another tutorial that address ...

Is there a way to have my MUI Typography component display a unique image cursor when hovered over?

After some testing, I found that setting the cursor to cursor: pointer works perfectly fine. However, my goal is to use a custom image as a cursor. The image is saved in both my src and public folders, but I seem to be struggling with the syntax when using ...

JavaScript: XHR struggles with managing multiple asynchronous requests

Hey there, I'm currently attempting to access a single resource multiple times with various parameters. Here's what I have so far: Essentially, I am making requests for the following domains: var domains = [ 'host1', 'host2&apos ...

Tips for running JavaScript code from a file

I'm currently working on launching a webpage in the Firefox browser using Python-Selenium web driver and injecting JavaScript code onto that loaded page. from selenium import webdriver from selenium.webdriver.common.keys import Keys driver= webdriver ...

What could be causing the webpage to not load when trying to scrape LinkedIn?

I am currently attempting to scrape data from a LinkedIn profile using Selenium. However, I am encountering issues with the driver not being able to load the page. I suspect that my IP address has been blocked and I am unfamiliar with concepts such as prox ...

When the text is lengthy, the button shifts its position

After creating two buttons, one with short text and the other with long text, I noticed that they are not aligned properly. Is there a way to align the second button even when the text is long? https://jsfiddle.net/ws2awc03/ var btn = document.createEl ...

How to Target a Specific Element Using its Class with jQuery

Hey there! I'm currently working with the following snippet of HTML code: <li class="grey"> <div class="row"> <button id="test" style="width:50%;" class="btn btn-blue-white cartBtn">Add to Cart</button> </div ...

Exploring paged content with selenium

I encountered an unusual pagination issue while scraping search results from The search results are grouped into 4 categories: 1) No search results found 2) Only one results page available 3) More than one but less than 12 results pages 4) More than 1 ...