How to click the dropdown option which is visible only by hovering action using playwrite python script - playwright-python

Playwright python script for action: click "To CSV" is dropdown visible only by hovering over the text "Export":
HTML:

I got you
This is how i currently do it on my Playwright script
page.type("#react-select-2-input", "January\n")
page.type("#react-select-3-input", "1\n")
page.type("#react-select-4-input", "1998\n\n")
page.click("#CSS SELECTOR EXPORT TAB", "MENU ITEM HERE\n")

Related

Cypress - A modal which is supposed to be visible after clicking an element is not opening up after the click

I am trying to validate a popup modal after clicking on an element.
During the test run, the click command is successfully completed but the modal is not visible.
I stopped running the test and then tried to click the element manually - even now the modal is not opened up!!
Tried click({ force: true }) and also the locators are correct.
//code
cy.get(locator for opening up the modal).click() // click is done
cy.get(locator for modal header).should('be.visible') // modal is not visible

How to use WinAppDriver to locate elements on Modal window of Modal window

I'm trying to automate a Windows Printer Driver Application on windows 10 pro with newest WinAppDriver v1.2.1.WinAppDriver.
The test script cannot locate any element on the Preferences Window, which is a Modal window's Modal Window.
The test scenario is as below:
The test script start notepad.exe, locate and click Print menu item, the Print Modal window shows.
Then locate and click the Preferences button on the Print Modal window, the Preferences Modal window shows.
Then try to click elements on the Preferences Modal Window, it fails.
Here is my sample code, using Appium-Python-Client library:
from appium import webdriver
desired_caps = {}
desired_caps["app"] = "C:\\Windows\\notepad.exe"
desired_caps["platformName"] = "windows"
driver = webdriver.Remote(
command_executor='http://127.0.0.1:4723',
desired_capabilities= desired_caps)
driver.find_element_by_name("ファイル(F)").click()
driver.find_element_by_accessibility_id("6").click()
# click elements on the Print modal window
driver.find_element_by_accessibility_id("1010").click()
# click elements on the Preferences modal window
driver.find_element_by_xpath("/Pane[#ClassName=\"#32769\"][#Name=\"デスクトップ 1\"]/Window[#ClassName=\"#32770\"][#Name=\"印刷設定\"]/Tab[#ClassName=\"SysTabControl32\"]/TabItem[#Name=\" 拡張機能 \"]").click()
driver.find_element_by_xpath("/Pane[#ClassName=\"#32769\"][#Name=\"デスクトップ 1\"]/Window[#ClassName=\"#32770\"][#Name=\"印刷設定\"]/Button[#ClassName=\"Button\"][#Name=\"設定(E)...\"]").click()
driver.find_element_by_xpath("/Pane[#ClassName=\"#32769\"][#Name=\"デスクトップ 1\"]/Window[#ClassName=\"#32770\"][#Name=\"印刷設定\"]/Window[#ClassName=\"#32770\"][#Name=\"セキュリティ印刷設定\"]/CheckBox[#ClassName=\"Button\"][#Name=\"セキュリティ印刷(S)\"]").click()
The WinAppDriver's log:
{"status":7,"value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters."}}
I also have tried relative xpath expressions, and by name or by accessibility id. Did not succeed.
I also have tried the WADLibrary client library. It had same phenomenon.
I also have tried some other versions of WinAppDriver, all failed except the old version of WinAppDriver v1.1.4
Is there any other way to locate elements on the descendant Modal window, Preferences Modal window?
The second modal window (Preferences Modal window ) is actually treated as a new window(whose window handle is managed by winappdriver). After switching the session to that window, and using relative xpath, I solved the problem.

wxPython: Toolbar Menu close event

I am creating a python app with wxPython 2.9.5 which features a system tray icon with a menu. I would like to receive an event when the menu is hidden/closed. On the mac the wx.EVT_TASKBAR_* event are not triggered. What event is there that I could Bind to?
I am asking as I want to toggle between a black and white icon on a mac.
https://gist.github.com/thomaschaaf/49e64bf2aa7c3078ede3
Update 1:
Attaching the binding to the app instead makes the event trigger on mac. Here is the example working like I want.
https://gist.github.com/thomaschaaf/7344891
I'm assuming you are creating the popup menu the normal way? Something like this:
menu = wx.Menu()
menu.Append(self.TBMENU_RESTORE, "Open Program")
menu.Append(self.TBMENU_CHANGE, "Show all the Items")
menu.AppendSeparator()
menu.Append(self.TBMENU_CLOSE, "Exit Program")
Well normally you'll also see a
menu.Destroy()
You should add a method call right after that so that your code looks something like this in the end:
menu = wx.Menu()
menu.Append(self.TBMENU_RESTORE, "Open Program")
menu.Append(self.TBMENU_CHANGE, "Show all the Items")
menu.AppendSeparator()
menu.Append(self.TBMENU_CLOSE, "Exit Program")
menu.Destroy()
self.onMenuDestroy()
Then you just add whatever needs to be done in the onMenuDestroy method.

Watir Help: click-no-wait and execute_script not working as expected

Using ruby's Watir gem, I'm trying to click a button that opens a javascript popup, then click 'ok' on the popup and I can't seem to do that. The button is in a frame in a frame. I have searched extensively and read the Watir wiki entry about javascript popups but nothing works.
I think this is because execute_script and click_no_wait are not working as expected.
For example, the following commands:
#browser.execute_script('window.alert = function() {}')
#browser.execute_script('alert("hello")')
create a javascript popup that says "hello" instead of the expected behavior of not doing anything.
The command:
#browser.button(:value, 'Submit').click
Clicks the button which creates a javascript popup. The script then hangs until I manually click 'ok' on the popup.
The command:
#browser.button(:value, 'Submit').click_no_wait
Does not click the button (or it does click the button and doesn't trigger the onclick event).
I have also tried:
Timeout::timeout(1) { #browser.button(:value, 'Submit').click }
and
Thread.new { #browser.button(:value, 'Submit').click }
But Timeout never throws an exception, causing ruby to hang until I manually click 'ok' on the popup, and Watir doesn't click when I run it in a new thread.
Would anyone be able to help or offer a solution?
Edit: The problem is that after #browser.button.click, the script hangs until the popup closes. #browser.alert.ok successfully closes the popup, but the script cannot execute #browser.alert.ok after the button is clicked because it hangs until the popup is closed. This catch-22 is supposed to be solved by click_no_wait, but click_no_wait is not clicking.
System information:
Windows 7 Enterprise 64 Bit
Internet Explorer Version 9.0.12
watir-4.0.2-x86-mingw32
ruby 1.9.3p286 (2012-10-12) [i386-mingw32]
There is an alert api (watir-classic and watir-webdriver) that you can use to interact with the javascript popup.
Try closing the popup using:
#browser.alert.ok
Update - Workaround:
This appears to be a bug with using Element#click_no_wait for elements in a frame. I have updated Issue 45 and will try to submit a patch.
In the mean time, adding the following monkey patch at the start of your script should solve the issue (ie the click_no_wait should not wait):
require 'watir-classic'
Watir::IE.new(true)
module Watir
class Frame
def attach_command
tag_name = #specifiers[:tag_name].join("' << '")
#container.page_container.attach_command + ".frame(:tag_name => Array.new << '#{tag_name}', :unique_number => #{unique_number})"
end
end
end

Accessing console and devtools of extension's background.js

I just started out with Google Chrome extensions and I can't seem to log to console from my background js. When an error occurs (because of a syntax error, for example), I can't find any error messages either.
My manifest file:
{
"name": "My First Extension",
"version": "1.0",
"manifest_version": 2,
"description": "The first extension that I made.",
"browser_action": {
"default_icon": "icon.png"
},
"background": {
"scripts": ["background.js"]
},
"permissions": [
"pageCapture",
"tabs"
]
}
background.js:
alert("here");
console.log("Hello, world!")
When I load the extension, the alert comes up but I don't see anything being logged to console. What am I doing wrong?
You're looking at the wrong place. These console messages do not appear in the web page, but in the invisible background page (ManifestV2) or service worker (ManifestV3).
To view the correct console open devtools for the background script's context:
Visit chrome://extensions/ or right-click the extension icon and select "Manage extensions".
Enable developer mode
Click on the link named background page (ManifestV2) or service worker (ManifestV3).
Screenshot for ManifestV2 extensions:
Screenshot for ManifestV3 extensions:
I had the same problem, in my case the logging was set to "Hide all" in the console tab in Chrome Developer tools.
I had not even realised this was an option, and I can't remember turning it off
For followers who wish to see the debug console for a "content script" of their chrome extension, it is available by doing a normal "show developer console" then use the dropdown arrow to selects its "javascript environment" then you'll have access to its methods, etc.
additionally
if you want to see content_script js file ( when "background" property is not set ) in manifest.json
"content_scripts": [{
"matches": ["<all_urls>"],
"js": ["popup.js"],
}]
"browser_action": {
"default_icon": "icon_32.png",
"default_popup": "popup.html"
}
then right click on extension icon and click on Inspect popup and developer window opens with popup.html opened , there you see console tab.
Similar to the answer of Michiel i also had a funny console configuration: A filter i dont remember setting:
After clearing the filter i saw the messages.
I had this problem as well. It seems as though my webpage was not updating to the newly saved script. This was solved by pressing Ctrl + refresh (or Ctrl + F5) in the chrome browser.
If we want to read messages printed to console from the popup page, we can click the extension icon to open the popup page, then do right click on the popup page anywhere, a dropdown menu will display, we just click "Inspect" menu to open the developer tool. Notice that the popup page must be keep opening. If it is closed(by window.close()), the developer tool will be closed too.
The other answer(s) work(s) for background.js but, if you are looking for console.logs from the popup then you can try:
var bkg = chrome.extension.getBackgroundPage();
bkg.console.log('foo');
I was developing using cra, and this worked for me.
For those developing extensions for Firefox:
TL;DR version: you need to use Ctrl+Shift+J to call up the browser console window, and click on the settings icon on the top right-hand corner and make sure that "Show Content Messages" is checked.
Longer explanation from a related stackoverflow question: How do I see the console.log output of a background script in a Firefox WebExtension?

Resources