By selecting the DIV element with the ID

I need to use selenium-webdriver to click on a specific div element identified by the id "send-button"

driver.findElement(By.xpath("//a[contains(text(),'Send anonymously')]")).click();
driver.findElement(By.id("send-button)).click();
(async function example() {
    let driver = await new Builder().forBrowser('firefox').build();
    try {
      await driver.get('https://onyolo.com/VFUF5VtxPJ');
      await driver.findElement(By.name('text')).sendKeys('test', Key.RETURN);
      await driver.findElement(By.xpath("//a[contains(text(),'Send anonymously')]")).click();
      await driver.wait(until.reload);
    } finally {
      await driver.quit();
    }
  })();

The website's HTML code shows the following:

<div id="send-button">Send anonymously</div>

Answer №1

If you want to execute pure JavaScript, you can use the executeScript method.

await driver.executeScript(`document.getElementById('send-button').click()`);

Answer №2

It appears that the correct xpath was missed in your query. Instead of 'a', 'div' should have been used.

//div[contains(text(),'Send anonymously')]

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

Struggling to access the <p> content below an <h3> tag with Selenium

Here's an example of some HTML code: <h3> A Sample Heading </h3> <p> Some Content </p> <p> Additional Content </p> <h3> Another heading</h3> <p> some text here </p> I want to retrieve the t ...

Trouble with selecting an image from the Android image gallery with Ruby Selenium

Is there a way to select an image from the Android image gallery grid view using Selenium webdriver in Ruby? I have tried selecting images by their ImageView ids, such as //ImageView[@id="someId"][1] or //GridView[@id="someId"]//ImageView[@id="someId"][1] ...

Getting the text value from a table in JavaScript is a straightforward process. By using

I am working with a table displaying available hotel rooms and want to change the text color to green if the room is marked as "available." Is there a way to check the innerHTML of a td element to see if it contains the word "available"? var status = do ...

Coordinating numerous AJAX requests in Angular with the help of Restangular

I am currently working on an Angular application that relies on $scope references to update the view using a factory singleton that exposes model and state objects. The challenge I face is ensuring that multiple AJAX calls (using Restangular) made by the f ...

Optimal JavaScript Technique: Synchronizing Browser Windows

In my html5/javascript application, multiple users can access and view the same set of data simultaneously. To illustrate, let's consider a scenario where they are all on a calendar page. For instance, user1 is browsing the calendar page while user2 ...

I'm looking for a JQuery plugin that can lock an element in place as you scroll through a webpage

My query is not regarding position:fixed. While scrolling down the page, I aim for the element to move down along with the page until it goes beyond the view of the browser. Once it goes out of the view, it should stay close to the top of the page, yet st ...

Can a resolution be found for this problem with the fixture?

software_test_001_run_browser.py from website_admin_pageobjects.run_browser_test.run_browser_test_manager import RunBrowserTestManager import pytest class Software_Test_001_Run_Browser: @pytest.fixture(scope="session") def test_run_brow ...

Convert traditional class-based styles to inline styles

Is there a tool available that can efficiently convert class-based styles to inline styles? I am designing an email and find it much easier and quicker to work with classes, but the final output requires inline styles. It seems like there should be softwar ...

NodeJS is throwing a `ReferenceError` because the `io` variable is not

I am working on a NodeJS project and I need to access a variable that is defined in my app.js file from another file. Is this possible? Here is my code: app.js var app = express(); var io = require('socket.io').listen(app); ... otherFile ...

Python script to extract price information from text using Selenium

I managed to put together a script that can open a website, log in, and search for specific parts using Selenium/Python. My ultimate objective is to iterate through a list of Part Numbers, extract the Price, and store it in a list. Currently, I am facing ...

Check out Mongo DB using Mongo compass

I am a beginner with MongoDB and Node. I successfully connected to Mongo as shown below: const mongoose = require("mongoose") mongoose.connect('mongodb://localhost/testaroo', { useNewUrlParser: true }) mongoose.connection.once('open', ...

Issue with HighCharts: Bar columns not extending to the x-Axis when drilling up

I am encountering an issue with HighChart/HighStock that I need help with. To illustrate my problem, I have set up a JSFiddle. The problem arises when a user drills down on a bar column, causing the y-axis to shrink and consequently making the x-axis appea ...

Step-by-step guide on how to have an AngularJS controller run continuously every 5 seconds once it has been initially called

My angular js file (app.js) contains the uuidCtrl controller, which triggers when called. When I want to call the controller 2 times, I have to load the page twice. However, I am looking for a solution to run it continuously after the first time it is call ...

Struggling to update the previousCode state with the useState hook in React

I'm having trouble understanding why the state isn't changing when using setPreviousCode in React and JavaScript. I'm trying to store the previously scanned text in the variable previousCode. import React, { useEffect, useState } from " ...

Different Ways to Conceal a Div Element Without Using Jquery

One interesting feature of my website is that users can select audio from a drop-down box, triggering the $.post function to display an auto-playing audio player in a div. However, I'm facing a problem because I don't want the audio player to be ...

unable to save the information to mongoDB

I've been attempting for the past 3 hours to save data from an HTML form to MongoDB using Node.js. When I click submit, it redirects to another page displaying the submitted data in JSON format, but it's not getting stored in the database. Here ...

Finding the target id of an appended element in an Angular application

I'm encountering an issue with retrieving the event.target.id in my AngularJS project. Here's the code snippet I am using: input-tag-to directive <input-tag-to></input-tag-to> Module: angular .module('emailClient').dire ...

jQuery Ajax Redirect Form

I am currently developing an HTML application with a form. Upon clicking the submit button, I initiate a server-side call using jquery.ajax(). However, when the server returns an exception, such as a Status Code 500, I need to display an error message on t ...

What is causing a single state update when setState is called twice in React?

It seems like I'm making a beginner mistake in React as I am trying to call the "addMessage" function twice within the "add2Messages" function, but it only registers once. I believe this issue might be related to how hooks work in React. How can I mod ...

Effortless glide while dragging sliders with JavaScript

In the code below, an Object is looped through to display the object key in HTML as a sliding bar. jQuery(function($) { $('#threshold').change(updateThreshold); function updateThreshold () { var thresholdIndex = parseInt($(&apos ...