Synthetic Canary - Click and Go to new Tab

0

I am trying to create a Python-Selenium solution in Synthetic Canary to automate clicking on various links on a website. If the link opens in the same tab, it works fine. However if the link opens in a new tab I am getting the following log in the Canary log

2024-07-10T11:11:58Z INFO: Synchronously Executing JavaScript in the current window/frame.: /* getAttribute */return (function(){return (function(){var h=this||self;function aa(a){return"string"==typeof a}function ba(a,b){a=a.split(".");var c=h;a[0]in c||"undefined"==typeof c.execScript||c.execScript("var "+a[0]);for(var d;a.length&&(d=a.shift());)a.length||void 0===b?c[d]&&c[d]!==Object.prototype[d]?c=c[d]:c=c[d]={}:c[d]=b}function ca(a){var b=typeof a;if("object"==b)if(a){if(a instanceof Array)return"array";if(a instanceof Object)return b;var c=Object.prototype.toString.call(a);if("[object Window]"==c)return"object";if("[object Array]"==c||"number"==typeof a.length&&"undefined"!=typeof a.splice&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("splice"))return"array";if("[object Function]"==c||"undefined"!=typeof a.call&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("call"))return"function"}else return"null";else if("function"==b&&"undefined"==typeof a.call)return"object";return b}function da(a){var b=typeof a;return"object"==b&&null!=a||"function"==b}function ea(a,b,c){return a.call.apply(a.bind,arguments)}function fa(a,b,c){if(!a)throw Error();if(2<arguments.length){var d=Array.prototype.slice.call(arguments,2);return function(){var e=Array.prototype.slice.call(arguments);Array.prototype.unshift.apply(e,d);return a.apply(b,e)}}return function(){return a.apply(b,arguments)}}function ha(a,b,c){Function.prototype.bind&&-1!=Function.prototype.bind.toString().indexOf("native code")?ha=ea:ha=fa;return ha.apply(null,arguments)}function ia(a,b){var c=Array.prototype.slice.call(arguments,1);return function(){var d=c.slice();d.push.apply(d,arguments);return a.apply(this,d)}}function m(a,b){function c(){}c.prototype=b.prototype;a.H=b.prototype;a.prototype=new c;a.prototype.constructor=a}function ja(a,b,c){var d=arguments.callee.caller;if("undefined"!==typeof d.H){for(var e=Array(arguments.length-1),f=1;f<arguments.length;f++)e[f-1]=arguments[f];d.H.constructor.apply(a,e)}else{if("string"!=typeof b&&"symbol"!=typeof b)throw Error("method names provided to goog.base must be a string or a symbol");e=Array(arguments.length-2);for(f=2;f<arguments.length;f++)e[f-2]=arguments[f];f=!1;for(var g=a.constructor.prototype;g;g=Object.getPrototypeOf(g))if(g[b]===d)f=!0;else if(f){g[b].apply(a,e);return}if(a[b]===d)a.constructor.prototype[b].apply(a,e);else throw Error("goog.base called from a method of one name to a method of a different name");}};/* 

My question is how to click on a element (which opens a new tab) successfully? And preferably switch to the new tab using driver.switch_to.window(driver.window_handles[1])

asked 4 days ago29 views
1 Answer
0

First, locate the link or element you want to click. You can use various methods like find_element_by_id, find_element_by_xpath, or find_element_by_css_selector. Once you’ve identified the element, use the click() method to simulate a click action:

element = driver.find_element_by_id("your_element_id")
element.click()

After clicking the link, a new tab will open. You can switch to the new tab using driver.switch_to.window():

# Switch to the new tab (assuming it's the second tab)
driver.switch_to.window(driver.window_handles[1])

Now you’re in the new tab context. You can interact with elements on the new page as needed.

profile picture
EXPERT
answered 4 days ago
  • I am facing the issue when clicking on the item. The new tab probably doesn't open in the Synthetic Canary ( headless Chrome ) and when I check the Canary log I see the 'Synchronously Executing JavaScript in the current window' message that I posted in the original post. FYI everything works just fine when I run the same thing on my local environment. I guess this might have something to do with aws_synthetics implementation of selenium maybe?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions