How to use if else logic in selenium ide chrome extension - selenium-chromedriver

Here is my task scenario… if id appears on the page then click
Else click other options
When I run the program it does work for the if condition as it appears on the page and its click the button but when I run the program for the other user and it doesn’t appear on the page it should click on the else condition but it's still looking for the if condition and gets failed.
How I can overcome this issue. Any idea, please. Thank you
I have tried selenium API control flow example as well as different forum example but did not work so far.
Command Target Value
store id
if ${id} = 'spellcheck-save'
click id=spellcheck-save
else
click css=.md-button > .fa-save
end
HTML Screenshot

Related

Selenium Click Does not work, but Manual Click works

my code currently is:
driver.get("http://w2.leisurelink.lcsd.gov.hk/index/index.jsp")
window1 = driver.window_handles[0]
facility_basic_version = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[3]/div[2]/div/div[3]/div/div[3]/div[1]/table/tbody/tr/td/div")
facility_basic_version.click()
# deselect selected captcha
window2 = driver.window_handles[1]
driver.switch_to.window(window2)
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH, '//div[#class="kbkey button red_selected sel"]'))).click()
#Solve Captcha here
#
#
#
# Click continue at specific time
while len(driver.find_elements_by_xpath('//div[#class="kbkey button red_selected sel"]')) < 4:
print('captcha not done')
pyautogui.moveTo(634, 586, 0.5, pyautogui.easeInQuad)
time.sleep(0.3)
pyautogui.mouseDown()
pyautogui.mouseUp()
print('captcha done')
time.sleep(100)
I have a section to solve captcha, but since I haven't implemented that part yet, for testing purposes I am still solving captcha manually.
The problem: after solving captcha, I want to click the continue button. However, if try to find the element, then click on button, I would be met with an error (site knows I am using automation). I tried just starting up chromedriver, doing all the steps the bot would do manually and click the continue button manually, and the site would allow me to continue to next page. Hence, I tried using pyautogui to simulate mouse movement but still site gives me error.
A captcha is by definition designed to prevent automation, so I'm not surprised this does not work.
You might still be able to find a workaround and this might help: https://www.browserstack.com/guide/how-to-handle-captcha-in-selenium

Chrome devtools erroneously pauses on exception in ignored script

Image speaks for itself; this script is on the debugger's ignore list; yet every time I trigger this exception it is paused upon. I cannot uncheck Pause on caught exceptions because I am trying to pause on a caught exception in another startup script.
Devtools says The debugger will skip stepping through this script, and will not stop on exceptions, but it's doing just that, it is not skipping this script.
I've tried several things, like unignoring/reignoring. Using canary, etc. I have this problem on both my windows and osx machines; so it doesn't seem to be particularly related to my environment.
I am wondering if anyone else has run into this and found a workaround. Thank you.
Problem remains unsolved. Leaving this post here with some unsucessfull tentatives of mine, so someone can build something based on them.
1. Devtools extension API
It is possible to create an add-on that can reach the Developer Tools window and even reach the Sources tab, but once there all I could do was creating new sidepanels or attaching a listener to code text selection changes: chrome.devtools.panels.sources.onSelectionChanged.addListener((x)=>{console.log("onselectionchanged");console.dir(x);});
This API was not enough, could not reach debug status or any interesting sidepanel.
2. Debugging the debugger with a JS debugger
By hitting ctrl-shift-i or ctrl-shift-j over a devtools debug window it is possible to open another devtools debug window, debuging the first one. From there it is possible to write code that detects the banner informing that the file was supposed to be ignored and then click on the continue button:
function breakpointskipper() {
bnr = document.getElementById("sources-panel-sources-view").querySelector("div.vbox.flex-auto > div > div > div > div.flex-none > div");
if (!bnr) return;
bnr = bnr.shadowRoot;
if (!bnr) return;
bnr = bnr.querySelector("div");
if (bnr.ariaLabel != "This script is blackboxed in the debugger") return;
btn = document.querySelector("div.scripts-debug-toolbar.toolbar");
if (!btn) return;
btn = btn.shadowRoot;
if (!btn) return;
btn = btn.querySelector("div > button[aria-label=\"Resume script execution\"]");
if (!btn) return;
btn.click();
}
It is possible to even attach this breakpontskipper() button presser to an event in the devtools window and automate things, but as soon as you close the debugger being debugged window, it is all over and you have to recreate the code and reattach again. As said before, I wasn't able to make any add-on reach here.
3. Debugging the debugger with a native debugger
One last available option would be using GDB to debug the DevTools and change its behavior, in the chromium documentation it is shown that they have debug symbols available but I didn't try this approach.
Please try the troubleshooting help, and share some feedback. Also it would help greatly if you pasted some script here.
Please check if your script black boxed like here
Did you accidentally turn on - break on all exceptions see here
Force a hard refresh, i.e. clear you cache like here
Turn off all break points, then do a restore, try again.
More from ref. on chromium bug site
Update 1: Can you please verify/double check that your file to ignore is actually added to the ignore list.
If you know upfront which files to ignore, head over to Developer Tools > Settings (Cog Icon) > Ignore List. Then add a file name or regex pattern you wish to exclude.
You should see something like

Difference in Chrome between `target="_blank"` and Right Click + `Open Link in New Tab`

Suppose I have a link to Google of the form
Google
There are a couple different ways to open this link in a new tab:
Left click on the link
Right click on the link and select Open Link in New Tab
I've noticed on an app I work on that there is different behavior between #1 and #2. For example, when I console out window.opener for #1 I get an object like
wheres #2 gives me undefined.
What are the differences between these two ways to open the link? I can't find any information about how a browser (in my case, Chrome), might handle these cases.
I had the same problem, two different behaviors were happening in those two cases in an application I was working on. I had to search everywhere to see why, only to find your question that helped me identify the problem.
in case #1, of course when you left click the link, the user is giving the developer the choice of whither to open in a new tab. whereas in case #2, the user is making the choice instead.
case #1 is like doing window.open(URL, '_blank');
case #2 is like opening a new tab and manually typing the URL;
the only thing I found is that when you open the URL with target blank (case #1), that new tab or window will link to the parent (opener) by window.opener until you close that window, the opener will be back to null
as far as behavior, the source code of the new URL may include logic on window.opener you may need to search if this was the case. I don't see why the browser would treat them differently, it has to be from the source code.

Chrome Extension -- Running executeScript in multiple new tabs at the same time

I'm building a Chrome Extension that has a popup.html with a search form. Like Travelocity or Kayak, the form includes checkboxes so the user can select which sites they want to query.
On submit, popup.js launches multiple new tabs based on the selected checkboxes. In the tabs.create() callback for each new tab I use executeScript to:
- (A) inject the user's query into the search form on each of the new pages, and
- (B) submit the search form on those pages.
My code is working when one checkbox is selected (i.e. new tab is launched), but when multiple new tabs are created simultaneously it appears that the executeScript isn't running consistently. Sometimes it works, and sometimes it doesn't.
This leads me to believe that there's some sort of issue with the timing of the script execution, but I'm not sure.
If you have any idea what's going on I'd love to hear your advice.
Also, I'd appreciate any resources on how to debug this sort of issue in the future.
Here's my code on github...
whole repo: https://github.com/rossmorey/SongSearch
manifest.json
popup.html
popup.js (most relevant file)
Many thanks!
Seems like when you open multiple tabs - your popup.html loses the focus and closes, so on tabs.create callbacks which injects your code will not be executed.
Try to create tabs with "active:false" option, like this:
chrome.tabs.create({url: stringToObj[org], active:false} ...
I think it would help you.
And also...
It's a bug in your SeSac inject-code: if no search type defined in popup window, block
input[value="undefined"]
will not be found, so "checked" property will be called on "undefined" and this will stop you inject script execution.

How to stop Netbeans opening my index on run?

When I run my project in Netbeans 6.8, it loves to open the index page automatically. It's annoying because I always keep a tab with the page I'm working on when I work, so I don't need this index page. It also makes my current page lose focus.
I have tried not specifying an index or my project URL, but then I can't run or save my project.
How can I prevent it from doing so?
In NetBeans 7.4:
Right-click your project, select 'Properties'
In left hand pane of popup, select 'Run Configuration'
In the right pane of the popup, in the bottom right corner of the list of fields, click 'Advanced...'
Select radio button 'Do Not Open Web Browser'
I ran into that issue as well. The solution is quite simple - go to the menu bar:
Run/Run File.
That's it. It will just run the current php script without going to the index.php.
Basically, you want to reopen the same page (refresh it ?) in the browser ? You can set settings in the project properties > run configuration, then chaange the index file or project url. But apart from that I am afraid that you can't do anything to prevent opening a new window on run. When you click 'run', netbeans says to your OS : "Hey, let's open that page (your_project_URL/index_file) now". The OS thinks and execute a command like "default_browser url", where the argument "url" is here your_project_URL/index_file. Then the browser thinks it's a new page to open, and BAM, opens a new page.
Just use shift+F6 which will open the current page with focus.