Paulliev Posted February 26, 2021 Posted February 26, 2021 Hello, I have an question about the webdriver udf. When I run my AutoIt script, I want it to open a new tab in my existing Chrome. Is this possible with Webdriver, or do I always need to create a new instance of Chrome?
Danp2 Posted February 26, 2021 Posted February 26, 2021 This topic was previously covered in the UDF support thread -- Latest Webdriver UDF Release Webdriver Wiki FAQs
Paulliev Posted February 26, 2021 Author Posted February 26, 2021 Thanks for your reply! I have got the following code. The problem is that it opens a new tab in the already existing Chrome, so that's good, but it won't navigate to the website. See the code below. Thanks in advance! expandcollapse popup#include "wd_core.au3" #include "wd_helper.au3" $_WD_DEBUG = $_WD_DEBUG_None Local $sDesiredCapabilities, $sSession ShellExecute("chrome.exe", "--remote-debugging-port=9222") SetupChrome() _WD_Startup() ; Create session and log in $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://app.teamleader.eu/tickets.php") ; Create new ticket _ChromeClickButtonId($sSession, 'loginButton') Sleep(5000) _ChromeClickButtonClass($sSession, '_3F4D5 _3FpQy _1ff4h _2Yigy _1-T6- e6RGs _31W-e') Sleep(2000) _ChromeSetInputValueById($sSession,'id_corc_id', ClipGet()) Sleep(1000) $sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@id='suggestions_corc_id']/a[@id='sg_corc_id_0']") $title = _WD_ElementAction($sSession, $sLink, 'attribute', 'title') If $title == "-3" Then MsgBox(0, "Helaas", "Deze klant staat niet in het systeem! Ga alsjeblieft zelf verder met invoeren!", 100) Else _ChromeClickDropdown($sSession, 'sg_corc_id_0') EndIf _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"debuggerAddress": "localhost:9222"} {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc
Nine Posted February 26, 2021 Posted February 26, 2021 You would need to create a new tab : _WD_Startup() Local $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_NewTab($sSession) _WD_Navigate($sSession, "https://app.teamleader.eu/?gotologin") “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Danp2 Posted February 26, 2021 Posted February 26, 2021 @Paulliev I can't run your code because it contains non-standard functions that you didn't include. If the original instance of Chrome wasn't launched with the remote-debugging-port option, then that is likely why your script isn't working. Latest Webdriver UDF Release Webdriver Wiki FAQs
Paulliev Posted February 26, 2021 Author Posted February 26, 2021 @Danp2 See my full code below. It should run now and you can see that the WD_Navigate won't work. expandcollapse popup#include "wd_core.au3" #include "wd_helper.au3" $_WD_DEBUG = $_WD_DEBUG_None Local $sDesiredCapabilities, $sSession ShellExecute("chrome.exe", "--remote-debugging-port=9222") SetupChrome() _WD_Startup() ; Create session and log in $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_NewTab($sSession) _WD_Navigate($sSession, "https://app.teamleader.eu/tickets.php") ; Create new ticket _ChromeClickButtonId($sSession, 'loginButton') Sleep(5000) _ChromeClickButtonClass($sSession, '_3F4D5 _3FpQy _1ff4h _2Yigy _1-T6- e6RGs _31W-e') Sleep(2000) _ChromeSetInputValueById($sSession, 'name', "TEST") _ChromeSetInputValueById($sSession,'id_corc_id', ClipGet()) Sleep(3000) $sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@id='suggestions_corc_id']/a[@id='sg_corc_id_0']") $title = _WD_ElementAction($sSession, $sLink, 'attribute', 'title') If $title == "-3" Then MsgBox(0, "Helaas", "Deze klant staat niet in het systeem! Ga alsjeblieft zelf verder met invoeren!", 100) Else _ChromeClickDropdown($sSession, 'sg_corc_id_0') EndIf _ChromeClickSaveButton($sSession, 'thebutton') Sleep(3000) _ChromeClickDescription($sSession, 'ahoy-button-base ahoy-button-icon ahoy-button-medium icon-only icon-24x24-edit-outline') _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"debuggerAddress": "localhost:9222"} {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc Func _ChromeSetInputValueById($sSession,$Id,$Value) $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='"&$Id&"']") _WD_ElementAction($sSession,$sButton,'value', $Value) EndFunc Func _ChromeClickButtonId($sSession,$Id) $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@id='"&$Id&"']") _WD_ElementAction($sSession, $sButton, 'click') EndFunc Func _ChromeClickSaveButton($sSession,$Id) $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@id='"&$Id&"']") _WD_ElementAction($sSession, $sButton, 'click') EndFunc Func _ChromeClickButtonClass($sSession,$class) $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@class='"&$class&"']") _WD_ElementAction($sSession, $sButton, 'click') EndFunc Func _ChromeClickDropdown($sSession, $Id) $sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@id='suggestions_corc_id']/a[@id='"&$Id&"']") _WD_ElementAction($sSession, $sLink, 'click') EndFunc Func _ChromeClickDescription($sSession, $class) $sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@id='description-info']/div[@class='ahoy-widget-header has-padding']/div[@class='ahoy-widget-actions']/button[@class='"&$class&"']") _WD_ElementAction($sSession, $sLink, 'click') EndFunc
Danp2 Posted February 26, 2021 Posted February 26, 2021 @Paulliev Remove or comment out this line and then rerun your code -- $_WD_DEBUG = $_WD_DEBUG_None Latest Webdriver UDF Release Webdriver Wiki FAQs
Paulliev Posted February 26, 2021 Author Posted February 26, 2021 @Danp2 Yes that works! The idea is as following. I want to go to /tickets.php without logging in. Is it possible that the user is logged in in the current Chrome session and that I can run my script without logging in?
Danp2 Posted February 26, 2021 Posted February 26, 2021 5 minutes ago, Paulliev said: @Danp2 Yes that works! The idea is as following. I want to go to /tickets.php without logging in. Is it possible that the user is logged in in the current Chrome session and that I can run my script without logging in? The script should run once you fix the issue in your $sDesiredCapabilities string. Unsure if there's a way to make it work without logging in. That would likely be determined by the browser's user profile in use. Normally, a webdriver session creates a brand new temporary user profile for that particular session. If you are attaching to a previously launched browser instance, then it should use whatever profile the browser was directed to use when it was first launched. P.S. Check the wiki for additional details on how to utilize an existing user profile Latest Webdriver UDF Release Webdriver Wiki FAQs
Paulliev Posted March 1, 2021 Author Posted March 1, 2021 Hello again, I tried to use ShellExecute to open a new tab in Chrome in the current Chrome session. That works perfectly! It opens a new tab in my Chrome where I'm already logged into teamleader. But my issue is that it won't run my clicks etc. I think this is because I don't use that Session anymore. Can I fix this and still using ShellExecute? See my code below: expandcollapse popup#include "wd_core.au3" #include "wd_helper.au3" $_WD_DEBUG = $_WD_DEBUG_None Local $sDesiredCapabilities, $sSession ; ShellExecute("chrome.exe", "--remote-debugging-port=9222") ShellExecute("chrome.exe","https://app.teamleader.eu/tickets.php", @SW_MAXIMIZE) SetupChrome() _WD_Startup() ; Create session and log in $sSession = _WD_CreateSession($sDesiredCapabilities) ; _WD_NewTab($sSession, "https://app.teamleader.eu/tickets.php") ; _WD_Navigate($sSession, "https://app.teamleader.eu/tickets.php") ; Create new ticket ; _ChromeClickButtonId($sSession, 'loginButton') Sleep(5000) _ChromeClickButtonClass($sSession, '_3F4D5 _3FpQy _1ff4h _2Yigy _1-T6- e6RGs _31W-e') Sleep(2000) _ChromeSetInputValueById($sSession, 'name', "TEST") _ChromeSetInputValueById($sSession,'id_corc_id', ClipGet()) Sleep(3000) $sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@id='suggestions_corc_id']/a[@id='sg_corc_id_0']") $title = _WD_ElementAction($sSession, $sLink, 'attribute', 'title') If $title == "-3" Then MsgBox(0, "Helaas", "Deze klant staat niet in het systeem! Ga alsjeblieft zelf verder met invoeren!", 100) Else _ChromeClickDropdown($sSession, 'sg_corc_id_0') EndIf _ChromeClickSaveButton($sSession, 'thebutton') Sleep(3000) _ChromeClickDescription($sSession, 'ahoy-button-base ahoy-button-icon ahoy-button-medium icon-only icon-24x24-edit-outline') _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc Func _ChromeSetInputValueById($sSession,$Id,$Value) $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='"&$Id&"']") _WD_ElementAction($sSession,$sButton,'value', $Value) EndFunc Func _ChromeClickButtonId($sSession,$Id) $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@id='"&$Id&"']") _WD_ElementAction($sSession, $sButton, 'click') EndFunc Func _ChromeClickSaveButton($sSession,$Id) $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@id='"&$Id&"']") _WD_ElementAction($sSession, $sButton, 'click') EndFunc Func _ChromeClickButtonClass($sSession,$class) $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@class='"&$class&"']") _WD_ElementAction($sSession, $sButton, 'click') EndFunc Func _ChromeClickDropdown($sSession, $Id) $sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@id='suggestions_corc_id']/a[@id='"&$Id&"']") _WD_ElementAction($sSession, $sLink, 'click') EndFunc Func _ChromeClickDescription($sSession, $class) $sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@id='description-info']/div[@class='ahoy-widget-header has-padding']/div[@class='ahoy-widget-actions']/button[@class='"&$class&"']") _WD_ElementAction($sSession, $sLink,
Danp2 Posted March 1, 2021 Posted March 1, 2021 @Paulliev You can't control the Chrome browser with Webdriver unless it is launched with the correct options. Latest Webdriver UDF Release Webdriver Wiki FAQs
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now