Interacting with AJAX links using Watir?

SOLVED:

Resolved my issue by implementing this code snippet:

b.link(id: 'm_wm_w5_m_lv_ctrl1_m_lnkWatch').fire_event :click

QUESTION:

Encountering difficulty clicking AJAX links using Watir.

The specific element I am trying to click is located at:

https://i.sstatic.net/Du1js.png

Provided HTML structure for reference:

<a id="m_wm_w5_m_lv_ctrl1_m_lnkWatch" href="javascript:__doPostBack('m_wm$w5$m_lv$ctrl1$m_lnkWatch','')" 
style="white-space:nowrap; font-size:11px;">New Listing (160)</a></td>

To interact with the element in Watir, I utilized the following command:

b.link(id: 'm_wm_w5_m_lv_ctrl1_m_lnkWatch').click

However, upon execution, a CSS popup appeared:

https://i.sstatic.net/ApDFj.png

Closed button within the CSS popup can be identified in the following manner:

<div id="NewsDetailDismissNew" class="btn mtx-btn-confirm enabled" title="Close">Close</div>

Despite attempting to interact with it through Watir:

b.div(id: 'NewsDetailDismissNew').click

No action was observed.

Further investigation led me to discover relevant javascript functions associated with the buttons:

<!--<div class="container" >-->
    <script>
    var cvMarkAsRead=function(  ){ return "Mark as Read"; };
</script>
    <script>
    var cvClose=function(  ){ return "Close"; }; //This is closes the CSS pop up as far as I can tell
</script>
    <script>
    var cvOK=function(  ){ return "OK"; };
</script>
    <script>
    var cvDismiss=function(  ){ return "I've Read This"; };
</script>
    <script>
    var cvPreview=function(  ){ return "Print Preview"; };
</script>   

    <!-- End NewsDetail modal -->

Seeking input on the following inquiries:

  1. How can I successfully trigger the "New Listings" link with Watir?

  2. Is there a method to effectively select the "Close" button on the displayed popup?

Although the link contains javascript, I am uncertain about leveraging b.execute_script within Watir. Despite referencing documentation and examples, I have encountered difficulties grasping the concept sufficiently to apply it accurately to my scenario.

Your assistance is greatly appreciated.

Answer №1

The following snippet of code resolved the issue I was facing. It simulates a click on New Listing and effectively loads all new listings without triggering an unwanted CSS popup.

I believe this code triggers the JavaScript by clicking the specified link.

I successfully activated the link by clicking it.

<a id="m_wm_w5_m_lv_ctrl1_m_lnkWatch" href="javascript:__doPostBack('m_wm$w5$m_lv$ctrl1$m_lnkWatch','')" 
style="white-space:nowrap; font-size:11px;">New Listing (160)</a>

Using the following Watir code:

b.link(id: 'm_wm_w5_m_lv_ctrl1_m_lnkWatch').fire_event :click

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

Module child-process not found

Why is it that when I try to run "require('child-process')" in the node shell, I receive an error saying "Cannot find module 'child-process'"? It seems like "child-process" should be a default library in Node. Any insights on what could ...

Transform a personalized Google map into a visual representation

I am facing a challenge with the following issue. I have implemented a custom overlay on a Google map and it works perfectly in the browser. However, my dilemma arises when I need to display an image with a marker for each point of interest on a different ...

Angular checkbox filtering for tables

I have a table populated with data that I want to filter using checkboxes. Below is the HTML code for this component: <div><mat-checkbox [(ngModel)]="pending">Pending</mat-checkbox></div> <div><mat-checkbox [(ngModel ...

Passing a class from a string value in Angular 2 using TypeScript

class SimpleComponent { } var myClass = 'SimpleComponent'; bootstrapComponents.push(myClass); // Ensure that 'SimpleComponent' class is passed and not just a string. Is there a way to transform a string value into a class object in ...

I need the language chosen using Lingui's Language Switcher (i18n) to persist throughout the app, even after a refresh

I have been experimenting with Lingui for internationalization (i18n) in my app. I followed the documentation and tutorial to create a language switcher, but I am unsure how to set it up so that the selected language persists throughout the app even after ...

Using Driver Wait Until Text in Selenium involves waiting for a specific text to appear on a

I'm currently experimenting with the driver wait function using this specific wait condition. My goal is to verify that the text displayed on a button is exactly "Sign Up". Below is the code snippet I am working with: driver.wait(until.elementTextIs( ...

What is the most effective way to loop and render elements within JSX?

Trying to achieve this functionality: import React from 'react'; export default class HelloWorld extends React.Component { public render(): JSX.Element { let elements = {"0": "aaaaa"}; return ( ...

Issue arises when trying to insert an image avatar onto a globe in three.js

I have successfully implemented a rotating 3D globe using three.js with the code provided below. HTML <canvas id="canvas"></canvas> JS let camera; let renderer; function main() { const canvas = document.querySelector('#ca ...

Unable to use setState on a component that is not mounted despite already calling componentDidMount

I'm facing a peculiar React Router issue that has me puzzled. Despite the fact that I can confirm the component in question is executing its componentDidMount lifecycle method, I am constantly receiving the warning "Can't call setState (or force ...

Error: SEC_ERROR_UNKNOWN_ISSUER encountered while using Selenium-wire with Firefox

While attempting to access a certain website and retrieve its network headers, I keep encountering the error message "SEC_ERROR_UNKNOWN_ISSUER". Surprisingly, there is no option to click on "Accept the Risk and Continue", only a button to go back. I&apos ...

Creating the code for Mocha to produce a fail response

I have been attempting to deliberately make the script fail by accessing/redirecting to 2 links before triggering the error case. Despite my efforts, Mocha still shows "1 passing" and only returns an error when it reaches the assertion. How can I ensure ...

What is the utilization of Puppeteer's slowMo feature in the Selenium Web Driver?

If you head over to https://github.com/GoogleChrome/puppeteer There exists an option to introduce a delay in every action Slow it down - the slowMo option slows down Puppeteer operations by adding a specified amount of milliseconds. It's another w ...

Exploring Angular for Creating Single Page Applications

Within the past few days, I delved into Angular and decided that creating a simple single page application would be a great starting project. This endeavor aims to pave the way for a much larger project in the future. I find myself grappling with understa ...

My project is experiencing issues with the execution of JavaScript codes

Greetings, I'm having trouble with my JavaScript codes. The following code works perfectly: function Choice() { var box = document.getElementById('searchh'); if (!count) { var count = 0; } box.onclick = function () ...

Formatting in Cx framework: Configuring right alignment and decimal precision on NumberField

Currently, I am involved in a project that involves UI development using Cx, a new FrontEnd framework based on React. You can find more information about Cx at One of the tasks in my project involves creating a Grid with filter fields located at the top ...

Exploring the Fundamentals of Skinning Animation in WebGL using Three.js

I've been exploring various demos on skinning in Three.js, but I'm struggling to understand if the imported model itself needs to be animated or if it's already animating from the modeling software and we just manipulate it? For example, ta ...

Utilizing Selenium to extract pricing information from websites

After realizing the lack of clarity in my previous post, I decided to delete it. The current issue I am encountering involves web scraping using selenium. The problem arises when trying to scrape a specific field with the following code: driver.get(' ...

What's the best way to add a border of 1 pixel solid #ddd to a select box with the help of jQuery?

I'm in need of some assistance, Many websites utilize the jQuery framework to add stylish effects to their selectboxes. Unfortunately, I am limited to using ie7 at my workplace and I want to include a 1px solid #ddd border around my selectbox (which ...

Display conceal class following successful ajax response

Upon clicking the button, the following script is executed: $.ajax({ url: "<?php echo CHILD_URL; ?>/takeaway-orders.php", type: 'POST', async:false, data: 'uniq='+encodeURIComponent(uniq)+'&menu_id=' ...

Chromedriver connection issue: Selenium Python WebDriver (Device currently unresponsive...)

I utilized Selenium to automate the website. Here is the code snippet I used: from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager browser = webdriver.Chrome(executable_path = 'SELE/chromedriver.exe') browser. ...