Struggling to choose an element with Selenium and Chrome?

I'm working on a script using Selenium and Chrome, but I'm facing issues with selecting and clicking on two specific elements. Let's take a look at the HTML code for these elements:

HTML of Element 1:

<td class="menuItem" id="tWlans" style=""><a href="frameWlan.html" 
id="cWlans" accesskey="W" onmouseover="highlight('Wlans')" 
onmouseout="removeHighlight('Wlans')" onclick="selectTab('Wlans')" 
onfocus="highlight('Wlans')" onblur="removeHighlight('Wlans')" 
target="mainFrame"><u>W</u>LANs</a></td>

HTML of Element 2:

<td class="listNoPad">  
<input type="TEXT" name="1.6.7.wlan_id" class="statictextboxlink" 
onclick="editThisWlan(this.value,this.name)" readonly="" size="7" value="7">
</td>

I've attempted to select the element by both id and XPath, but neither method seems to work.

function siteNavigate() {
sleep(4500);
driver.findElement(By.xpath('//*[@id="cWlans"]')).click();  
//driver.findElement(By.id('cWlans')).click();
}

Any help or suggestions would be greatly appreciated.

Edit:

// JavaScript functions
...
// CSS styles
...
// Additional scripts
...

Edit 2: Error message from Node.js:

// Error details
...

Answer №1

Apologies for the confusion earlier. It took me a while to realize that the webpage actually contained multiple nested iframes, causing some issues along the way. There were four frames in total, with some changing based on context and others remaining static after login. The challenge lay in determining which frame to switch to and keeping track of the current focus.

const {Builder, By, until} = require('selenium-webdriver');
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).build();

driver.get('http://sitetonavigate.com');
driver.manage().window().maximize();
driver.findElement(By.name('bSubmit ')).click();        

function sleep (time) {
  return new Promise((resolve) => setTimeout(resolve, time));
}

// Waiting for Chrome to load fully before launching AutoIT login script
sleep(4500).then(() => {
    autoIT();
});

function autoIT() {
    var child_process = require('child_process');
    var workerProcess = child_process.execFile("C:\\Selenium\\autoITscript.exe");
    sleep(2500).then(() => {
        siteNavigate();
    });
}

function siteNavigate() {
    driver.switchTo().frame("banner");
    driver.findElement(By.id('cWlans')).click();

    // Selecting correct WLAN
    sleep(2500).then(() => {
        driver.switchTo().defaultContent();
        driver.switchTo().frame("mainFrame");
        driver.switchTo().frame("content"); 
        driver.findElement(By.xpath('/html/body/form/table[3]/tbody/tr[8]/td[2]/input')).click();
    });
}               

Answer №2

Here are the steps you can take:

Step 1:

 driver.findElement(By.id('tWlans')).click(); 

Step 2:

 driver.findElement(By.name('1.6.7.wlan_id')).click();

Answer №3

When you click on the TD element with the ID of tWlans, it is likely because you are trying to interact with the A tag inside it. To do so, you can use the CSS selector #tWlans > a. Below is the code snippet for this action, including a wait statement that may or may not be necessary.

WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#tWlans > a"))).click();

The second element mentioned was not provided in the full HTML shared, making it unclear if it's unique. However, you can attempt using these two CSS selectors:

input[name='1.6.7.wlan_id']
input[onlick^='editThisWlan']

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 pause execution until receiving an API response in a separate function?

Seeking guidance as a newcomer to JavaScript/NodeJS, I am struggling to grasp the concept behind a function I am working on. The purpose of this function is to execute an action based on the response received from an API post request within a separate func ...

Unable to unregister event listener using RemoveEventListener function

After attaching an event listener to my SVG image to run some code once the image is loaded, I encountered a bug in my SVG generation code that sometimes prevents the file from loading. In this scenario, when the user clicks another button, I want to remov ...

Comparing Sails.js middleware and policies: what sets them apart?

I've been tasked with upgrading a Sails 0.10.5 application to Sails 0.12.x, which serves as an API for a mobile (cordova/hybrid) client. During the migration process, I aim to reconstruct certain parts of the application using the correct Sails pract ...

Unable to see the tokens on the connect four board when using Javascript and HTML

I'm currently developing a game of connect four using javascript, html, and css. I'm encountering an issue with the refreshGrid() function in game.js. At the moment, when I run my html file, I only see an empty board. The function is meant to ena ...

How can I add rows to the tbody of a table that is already inside a div container?

I have an existing table and I want to append a tbody element to it. Below is an example of the HTML table: <div id="myDiv"> <table class="myTable"> <thead> <tr> <th>ID</th> ...

Vue should only activate the element that has been clicked on

I'm currently working on my first Vue project and encountering an issue with triggering a child component within a table cell. Whenever I double click a cell, the `updated` event is being triggered in all child components associated with the table cel ...

Guide to setting up parameterized routes in GatsbyJS

I am looking to implement a route in my Gatsby-generated website that uses a slug as a parameter. Specifically, I have a collection of projects located at the route /projects/<slug>. Typically, when using React Router, I would define a route like t ...

The AngularJS $filter(date) function is causing incorrect format outputs

Hey there! I've come across an issue with my AngularJS filter, where it's supposed to return a date in a specific format. However, when I try the following code: var input = '2015-08-11T13:00:00'; var format = 'yyyy MMM dd - hh:mm ...

How can I utilize module imports with the support of web browsers?

I'm currently troubleshooting why my script tags are not functioning in my html file. I discovered an article mentioning the ability to import modules into browsers using a script tag with a module type. The information was found on this site: https:/ ...

Tips for using jQuery to create a delete functionality with a select element

I'm relatively new to utilizing jquery. I decided to tackle this project for enjoyment: http://jsbin.com/pevateli/2/ My goal is to allow users to input items, add them to a list, and then have the option to select and delete them by clicking on the t ...

Unveiling the ApplePay token with VueJS

I'm facing an issue with decrypting the ApplePay token in my Vue app, using a specific package. The error message I'm receiving is quite puzzling and I'm struggling to comprehend it. Simply checking if the package is installed by running th ...

Encountering the NullInjectorError when Angular 17 is unable to find a provider for the function(options)

I'm new to Angular (version 17) and encountered an error: ERROR Error [NullInjectorError]: R3InjectorError(Standalone[_LoginPageComponent])[function(options) { -> function(options) { -> function(options) { -> function(options) { -> functio ...

Checkbox value not being accurately retrieved by Struts2 page

I have a form that captures phone information for two different phones, with each phone having its own set of details. If the user enters the same phone number for both phones, the second checkbox is automatically checked using the JavaScript code below: ...

What is the best way to retrieve JSON data in a React application?

useEffect(async () => { const fetchPostData = async () => { const response = await axios("") setPosts(response.data) } fetchPostData(); }, []) Rendering : posts.map(post => <li>{post.name} ...

If the number exceeds 1, then proceed with this action

I currently have a variable called countTicked, which holds an integer representing the number of relatedBoxes present on the page. I am in need of an if statement that will perform certain actions when the value stored in countTicked exceeds 1. if (!$(c ...

What is the method for executing a server-side script without it being transmitted to the browser in any way?

Although the title may be misleading, my goal is to have my website execute a php file on the server side using arguments extracted from the html code. For example: document.getElementById("example").value; I want to run this operation on the se ...

Javascript skips the if-else block when used asynchronously

I'm struggling with an if-else block in my code that is not getting executed as expected. Despite rearranging the code to ensure the if-else condition is met before calling http.get(), I am still facing issues. This problem arises while working with A ...

Having trouble accessing the card number, expiration date, and CVC in vue using Stripe

Although I am aware that Stripe securely stores all information and there is no need for me to store it on my end, I have a specific requirement. When a user begins typing in the input area, I want to capture and access the card number, expiry date, and ...

Encountering a 404 error in Codeigniter when making an AJAX call

After successfully implementing an upload form with ajax, I encountered some issues when attempting to delete uploaded photos. Initially, I received a "csrf protection error," which led me to disable csrf protection, only to then encounter a "404 not found ...

Mysterious codes are active and causing redirecting actions to unfamiliar websites upon clicking

Issue:- Upon clicking on the NAVBAR menu or any div element on my bootstrap website, it sometimes redirects to unwanted ads or unfamiliar links in a new tab. Links imported from hosted file:- <link rel="stylesheet" type="text/css" href="css\boot ...