Feb-17-2019, 04:04 PM
Feb-17-2019, 04:39 PM
gahhon Wrote:but it still same errorWhat's the error?
You could post all of your code and not just one line.
Do not post image of HTML code.
Can post in forum with code tag or better for HTML CodePen or JSFiddle.
Example Pen,you see that i have put
id="txtAccessCode"
.When i test local with that html code it work,it send
abc123sample
to input field.from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.keys import Keys import time from bs4 import BeautifulSoup #--| Setup options = Options() #options.add_argument("--headless") browser = webdriver.Chrome(executable_path=r'C:\cmder\bin\chromedriver.exe') #--| Parse or automation browser.get('file:///E:/div_code/scrape/local1.html') time.sleep(3) browser.find_element_by_id("txtAccessCode").send_keys("abc123sample") time.sleep(5) browser.quit()
Feb-17-2019, 05:36 PM
(Feb-17-2019, 04:39 PM)snippsat Wrote: [ -> ]gahhon Wrote:but it still same errorWhat's the error?
You could post all of your code and not just one line.
Do not post image of HTML code.
Can post in forum with code tag or better for HTML CodePen or JSFiddle.
Example Pen,you see that i have putid="txtAccessCode"
.
When i test local with that html code it work,it sendabc123sample
to input field.
from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.keys import Keys import time from bs4 import BeautifulSoup #--| Setup options = Options() #options.add_argument("--headless") browser = webdriver.Chrome(executable_path=r'C:\cmder\bin\chromedriver.exe') #--| Parse or automation browser.get('file:///E:/div_code/scrape/local1.html') time.sleep(3) browser.find_element_by_id("txtAccessCode").send_keys("abc123sample") time.sleep(5) browser.quit()
Sorry my bad.
<div class="title"> <span id="lbllgnHeader">Hello. Please Login</span> </div> <div id="signin_forms" class="step1"> <div class="input_row"> <span id="lblUsername">Username</span><input name="txtAccessCode" type="text" id="txtAccessCode" class="signin_input username" placeholder="Enter Username" maxlength="20"></div> <span class="input-error-msg"> <label id="lblMessage" style="word-wrap: break-word"> </label> </span> <div class="login_btns"> <div class="btn login_btn"> <a id="cmdLogin" onclick="javascript:if(loginUser(frmLogin)==false) return false;" tabindex="0" title="NEXT, GET SECRET WORD" href="javascript:__doPostBack('cmdLogin','')">NEXT, GET SECRET WORD</a> </div> </div> </div> <style type="text/css"> <!-- .red { color: #F00; } --> </style> <div class="help_links"> <table> <tbody><tr> <td width="40%"> I am a first-time user</td> <td width="40%"> I have a problem logging in</td> </tr> <tr> <td> <span class="icn">></span><a href="../lgn_default.aspx?usercontrol=Login/lgn_first_time_enrol_card_sel" onclick="javascript: if( isClickedTwice() ) return false;">I want to Register</a> </td> <td> <span class="icn">></span><a href="../lgn_default.aspx?usercontrol=Login/lgn_pswd_reset_card_sel" onclick="javascript: if( isClickedTwice() ) return false;">Forgot Password</a> </td> </tr> <tr> <td> <span class="icn">></span><a href="http://www.rhbgroup.com/general-info/faq/howtoregister.htm" target="_blank">How to Register</a> </td> <td> <span class="icn">></span><a href="http://www.rhbgroup.com/general-info/faq/forgot_username.htm" target="_blank">Forgot Username</a> </td> </tr> <tr> <td> <!-- <span class="icn">></span><a href="">Tutorials</a> --> <span class="icn">></span><a href="https://rhbgroup.com/products-and-services/personal/rhb-now/media" target="_blank"><strong><font color="orange">Watch Quick Guides</font></strong></a></td> <td> <span class="icn">></span><a href="../lgn_default.aspx?usercontrol=Login/lgn_re_enrol_card_sel" onclick="javascript: if( isClickedTwice() ) return false;">Re-Registration</a> </td> </tr> </tbody></table> </div> <!-- SIGN IN ENDS -->
from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.keys import Keys import time # Google Chrome Driver Setup def chromeSetup(): options = webdriver.ChromeOptions() options.add_argument("--start-maximized") options.add_argument("--disable-infobars") options.add_argument("--ignore-certificate-errors") options.add_argument("--disable-extensions") options.add_argument("--disable-gpu") options.add_argument("--log-level=3") return options options = chromeSetup() lgDetails = readExcel("RHB") driver = webdriver.Chrome(options=options, executable_path=r'chromedriver.exe') # Close extra tab when launch chromedriver.exe driver.switch_to.window(driver.window_handles[1]) driver.close() # Navigate back to first tab and redirect to desire URL driver.switch_to.window(driver.window_handles[0]) driver.get("https://logon.rhb.com.my/") time.sleep(3) # 1st phase of login ##driver.find_element_by_id("txtAccessCode") driver.execute_script("document.getElementById('txtAccessCode').value = 'abc'")I was encountered that error of
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license()" for more information. >>> ========== RESTART: C:\Users\Jack Wong\Desktop\Python\rhb - hold.py ========== Traceback (most recent call last): File "C:\Users\Jack Wong\Desktop\Python\rhb - hold.py", line 45, in <module> driver.find_element_by_id("txtAccessCode").send_keys("abc123") File "C:\Users\Jack Wong\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 360, in find_element_by_id return self.find_element(by=By.ID, value=id_) File "C:\Users\Jack Wong\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element 'value': value})['value'] File "C:\Users\Jack Wong\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Users\Jack Wong\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"txtAccessCode"} (Session info: chrome=72.0.3626.109) (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.17134 x86_64)So far I had tried get the Name or XPath but they result still the same.
Then I go to browser console try to catch the element by using JS.
document.getElementById("txtAccessCode").value() = "something"
and it return me expected result.
Thanks for advanced information
Feb-17-2019, 07:35 PM
As it's a Bank site,there may be several security step to avoid automation and parsing.
So i don't think i want to look further into this for login to a Bank site.
So i don't think i want to look further into this for login to a Bank site.
Feb-18-2019, 02:23 PM
(Feb-17-2019, 07:35 PM)snippsat Wrote: [ -> ]As it's a Bank site,there may be several security step to avoid automation and parsing.
So i don't think i want to look further into this for login to a Bank site.
Yeah I am understand that. But this is for own sole-provider business banks usage.
As I have to keep changing password after a certain periods. I design this for myself & my partner just to avoiding keep enter the wrong credential and got profile locked.
We must go to the home branch and unlock and with document supports.
Hope you are understand. Thanks