EDIT
There was a bug in Firefor driver. It was solved by using chrome driver.
I am new to python and I am developing a script that will send message on whatsapp using webwhatsapp.
But I am not able to write anything in text inputfeild using driver.send_key('message') method.
<input type="text" class="input input-search" data-tab="2" dir="auto" spellcheck="false" title="Search or start new chat" value="">
CODE
contactSearch=driver.find_element_by_xpath('//*[#title="Search or start new chat"]').click()
contactSearch.send_keys("name")
I have tried contactSearch.clear() and click() method also but the input remains blank.the code is from https://web.whatsapp.com/ go there login and there will be a feild called Search or start new chat.I want to input text in that field.
You are not logged in to whatsapp in your selenium session and hence there is no "New chat" button. By default, selenium starts a brand new browser session with default preferences, no browser history or cookies.
Related
I am trying to automate navigation in affinity meterflow portal in python using Selenium Webdriver.
I am struck in the login page.
I am able to set the user name and password
username = driver.find_element_by_xpath(r"/html/body/div[1]/div[1]/div/div/form[1]/table/tbody/tr[1]/td[2]/input")
username.send_keys("User#domain.com")
pwd = driver.find_element_by_xpath(r"/html/body/div[1]/div[1]/div/div/form[1]/table/tbody/tr[2]/td[2]/input")
pwd.send_keys("mypassword")
pwd.send_keys(Keys.ENTER)
When I manually fill the user name and password in the appropriate fields and press the enter key, its logging in. But the above code is not working.
On close analysis of the source there is a hidden field whose value is getting changed from
<input type="hidden" name="javax.faces.ViewState" id="j_id1:javax.faces.ViewState:0" value="AvEhv0iIxDgCLcuPIgfN2f808sVZibdxg4w9lzSW9kl1SRH+rDQh5O/ltokm4QQqxcEUOBH8Y+NsxXcjw15Fa61+DDAH0uYIre/R/FLomcd4+h9nwsXdxsdtwdurZhkiMyd9h4GtCGqUJMBmphStXUTfTI34JknbTsTWg/b6qyX0y998CBj5sdpe8Iy3d/DNrhI3PTcafgTKfX5wxjO0ODEqqIqwKI34glGzMtQDwbaXtnuSWpEeyap5eU+wIdyreWuT2cXEGPneNSMeVKv4eggTcsQuL8C0CcF/gXtwQWC1rPF4y8PT9nhzVPiMqqv0SRG7lGDJr1VgyMbu7E3Zp9iGN0YLuygAERmM0eF3wiLWGcMuZLHxWsP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3spAMQ3TavYFj3Y2SB/ji0dZLDL23JdHbwkUXLR5HU23kZpU2zFkKZajY51PoX7DAfQAAJtYcieaQCfz0Sg/fP/I293S9z2hbkW7Pxr7wd1MF2DPi6ZEg769ZN1BejAUVw5aYzH0H5IdM6eotnWGy/5qTsEcgu41HTX8FuizFuvjmEY5/0ytGrTEpSAxRTK+FsVRQyPvI9QFkxBPlYN/xWt2QypiyjESPYlUirMfx0SPod5cp4uoy5U=" autocomplete="off" />
to
<input type="hidden" name="javax.faces.ViewState" id="j_id1:javax.faces.ViewState:0" value="vxhxNm+TdYqneN2V2XbjAbiChJzVJEUQy8E7MyCiNY4ighg27kGSgdUeaaFCHRhAeo1TLffBU4UozQIpF6sgjQaZ+WWSy97MTQc/kBg148E9kgPrNe33bOT/MGM61T57kzewV5qLGdvBMV3j3p4DQmcwG7uD2P1a+s+v0kMWeNdiS/SnydwrDYHPUxA60PmG+7zIcbKrai1uhrjiTW3uIQ5HukwTvZS/eeUibJqtB3KdwFe4qkQjzEI2O3TFIoEhE1Oe5zUj2m71J0ZMIu2VnLGJGeZGYgRUMMTgnUkDkQlOO3H/Lzwtnp8EjECbB5LxI4IkxBI/o/5LvpbENRhsBCCU/gUUeFiUxVnFKwbPSIJbjj8Xk3h1XrShqwFFtaOpwfFRW3gs7WMzuJ/pG1wJRFNN0GcGsNpyTMs20puJg6A74oNPvESaPWJDY0Z/lOjO263MElqVqUjqZ508fc9cZAad8NzNId3/UEA9LklhJjkLjoI+iWAij3oNu9q+vRyu5lH9UfnnoKpjrbBLOjG5UFkd6LoW0+ae0odD06nQdJINnF4HSe++9jQKdBGgj9Rk4EbdyTR1Y8zkd9gLNO5K6OhNQ3DfpjOmMV6WSUKPdS1mzlQdnMeTFkH3CNsbeCh4X/GwgZMpstmWXqDhAZvu5FtYU+KSjBkTY8iEwIyK1poWgI3Ilk31QmZVeOiTTf3251KMgUgOaP/FG+00iRz6vvr8qO/Vb8ONEKmMYTy4bC7PoPU6vxCp1a8nQD1vjoT1kOINL27E609oUcYyoW9rGdbOBbQ8VLUct7tlwOgdRTI2T2Lz72ZN8eba+mK9VlWZRyU/dXwZWWz+9NHYcHxlrlV88WSilLxbckkhbZjM1X4WCcHhCS5WrJ46Vi3bwlqGnjZ9z1Gr4IW2qMBkOBgH6bn/rIHZDc2idfiiHkSxbAAV1uhbLjji7IA8aRH/qUtwGqv/BQDwj6PVXQomjwMs/K0OVZeshiDedt9xJmIXwK3nr6Kv2Guy+AKQnfYk29yuX/HxUDCQ+6YmEa9tHLg4gn2gSbU0xlbhZRWFxfnalgwt/K9FGUbVGSNrO4r348kyMPHj7dTq9siwu3fBYBBoVcvVPAqsE7MHe+nqolVfo6vmdHq3kMvQS5reuP0HCXnMVsyWnU3SPfNTpX5LpdfO8SzV6KIk53J9w6Q76y3drndmJQ7HykGrGc3SNA60xdn/klJffSOjSYgEo914IJGhd1Lx+8cwPaUIojADMRc/bBX/h1oHxiBAXDLYHJMBlLlQ866gLxH4Jt9hKUjDRjzQM6uTiJkztuJdYtFGJP4tDbqzMNHDq5SMOeuIuvWpRGVd6yUe7YEGfW058G7g/qr6nkP7xs/FK/8SeiQ9Ooc/GjGvZFAvSv9RTJJ0ZtbfSwW/7g1l7YRBdGi0hISJOobKCEVvdZgbPVw3FTJJVcZq9PI0DyQDqe1qg6TyPqngJIRl/uyUM654XoE6dfczUDQ43mCTUBv9O/VttiveJSoXvBqk+9CtgzjeOtZiHtQEXpNiuUd+lLYnlTTZ0pLytqB/kS+fCDVfr+sa3u1ybZuMVcVRUBB0V4SBqEFCO/rarED+DvME9JeUYZSDAfTDT5gHSM6CoetL/JCSw4Cg1FViL5Jmn7eBhck/5N5SoHmQfFz8etJofyCbF82ofyAdaUESabKbe8Ff4JG0TEbR2PsNgP8=" autocomplete="off" />
When we manually hover the login button with mouse.
To achieve the hovering effect I tried the move_to_element function
n = driver.find_element_by_xpath(r"/html/body/div[1]/div[1]/div/div/form[1]/table/tbody/tr[1]/td[2]/input")
a.move_to_element(n).perform()
But unfortunately its not moving my mouse cursor over the element (Input box). Where am I going wrong?
Any inputs in this regard will be helpful. Any other approach to achieve it is also welcomed.
Thanks.
--Subramanian
portfolio123.com recently changed their whole website.
When a login submit button has no ID label:
<button type="submit" class="btn btn-primary" ng-disabled="data.loading">{{ data.loading ? 'Please wait...' : 'Submit' }}</button>
how would one do an automated login? (this is how you "normally" do it
signInButton = browser.find_element_by_id('signIn')\n",
"signInButton.click()\n
I am trying to do this:
https://www.hongkiat.com/blog/automate-create-login-bot-python-selenium/
Doing a get by class btn btn-primary could work... But there are 4 buttons on this page that use that class...
Did they purposely make this modification so bots cannot get in?
You could use xpath
browser.find_element_by_xpath('//button[text()="Submit"]').click()
You can test it identifies the element correctly by pasting the string in to a browser console between $x('') symbols
e.g.
>> $x('//button[text()="Submit"]')
I'm trying to build a web scraper with selenium that pulls pricing and nutrition data from https://www.hannaford.com/home.jsp for a school project. The difficulty is that pricing data is store specific. To solve this I have used selenium to enter the users zip-code on the website. Afterwards, a pop up window opens with five of the nearest stores. The program needs to select a store from these locations.
I've copied the x-path of the button that selects the first store and set it to be clicked, but selenium still does not continue past the popup.
Here is my code:
hannaford =
"https://www.hannaford.com/home.jsp"
#opens website
driver.get(hannaford)
driver.find_element_by_xpath("""//*[#id="node01"]/a""").click()
driver.find_element_by_xpath("""//*[#id="pageContentWrapperInner"]/div[2]/div/div[1]/p[2]/a""").click()
inputElement = driver.find_element_by_xpath("""//*[#id="cityStateZipLayer"]""")
inputElement.send_keys(zip)
inputElement.send_keys(Keys.ENTER)
#attempt to select store in popup
driver.find_element_by_xpath("""//*[#id="glo-store-results-layer-store-list"]/div[1]/span/form/a""").click()
and here is the html associated with the link I'm trying to click:
<span class="fr rightSide">
<form class="fr" action="/custserv/save_user_store.cmd" method="post" name="selectThisStoreForm"><input type="hidden" name="form_state" value="selectThisStoreForm"><input name="storeId" type="hidden" value="21185" autofillparam="ON"><a href="" onclick="javascript:saveUserStoreNoClose('21185');return false;" class="altLink">
<input class="shopNow" type="image" autofillparam="ON" src="/assets/hf/assets/images/buttons/btn_shopNow.gif" border="0" alt="Shop Now"></a>
</form></span>
How could I resolve this issue. Is it even possible to select dynamic elements like this in selenium?
I was doing some web scraping with python (Linkedin site) and got stuck with the following 2 issues: 1) How do I input text on a search bar? 2) How to click a button? First, this is the search bar code:
<input aria-autocomplete="list" autocomplete="off" spellcheck="false"
placeholder="Búsqueda" autocorrect="off" autocapitalize="off" id="a11y-
ember6214" role="combobox" class="ember-text-field ember-view" aria-
expanded="false">
To input the text I was using the xpath (and it works) but it changes every time I login into the site:
search = driver.find_element_by_xpath('//*[#id="a11y-ember997"]')
search.send_keys('MedMake')
So could I use instead part of the input bar code above so that I can rerun my script multiple times?
My second point is 2) how to click a button. Again I was using the xpath but it changes after every login. My code was:
button = driver.find_element_by_xpath('//*[#id="nav-search-controls-wormhole"]/button')
button.click()
I inspected the button code and I would instead like to use data-vertical="PEOPLE" or any other of this unique fields (the tag button is not enough since there are many buttons on Linkedin site). By the way,how are all these inner fields called? I believe part of my problem arises from the lack of html code understanding.
<button data-vertical="PEOPLE" data-control-
name="vertical_nav_people_toggle" data-ember-action="" data-ember-
action-8620="8620" data-is-animating-click="true">
Gente
</button>
If id attribute values are dynamic you can use other attributes with static values:
search = driver.find_element_by_xpath('//input[#placeholder="Búsqueda"]')
search.send_keys('MedMake')
button = driver.find_element_by_xpath('//button[normalize-space()="Gente"]')
button.click()
First one use xpath
//input[contains(#class,'ember-text-field')]
Second one use the xpath
//button[#class='vertical_nav_people_toggle']
Python: 3.4.1
Browser: Chrome
I'm trying to push a button which is located in a form using Selenium with Python. I'm fairly new to Selenium and HTML.
The HTML code is as follows:
<FORM id='QLf_437222' method='POST' action='xxxx'>
<script>document.write("<a href='javascript:void(0);' onclick='document.getElementById(\"QLf_437222\").submit();' title='xxx'>51530119</a>");</script>
<noscript><INPUT type='SUBMIT' value='51530119' title='xxx' name='xxxx'></noscript>
<INPUT type=hidden name="prodType" value="DDA"/>
<INPUT type=hidden name="BlitzToken" value="BlitzToken"/>
<INPUT type=hidden name="productInfo" value="40050951530119"/>
<INPUT type=hidden name="reDirectionURL" value="xxx"/>
</FORM>
I've been trying the following:
driver.execute("javascript:void(0)")
driver.find_element_by_xpath('//*[#id="QLf_437104"]/a').click()
driver.find_element_by_xpath('//*[#id="QLf_437104"]/a').submit()
driver.find_element_by_css_selector("#QLf_437104 > a").click()
driver.find_element_by_css_selector("#QLf_437104 > a").submit()
Python doesn't throw an exception, so it seems like I'm clicking something, but it doesn't do what I want.
In addition to this the webpage acts funny when the chrome driver is initialized from Selenium. When clicking the button in the initialized chrome driver, the webpage throws an error (888).
I'm not sure where to go from here. Might it be something with the hidden elements?
If I can provide additional information please let me know.
EDIT:
It looks like the form id changes sometimes.
What it sounds like you are trying to do, is to submit the form, right?
The <a> that you are pointing out is simply submitting that form. Since that is being injected via JavaScript, it's possible that it's not showing up when you try to click it. What i'd recommend, is doing:
driver.find_element_by_css_selector("form[id^='QLf']").submit()
That will avoid the button, and submit the appropriate form.
In the above CSS selector, i also used [id^= this means, find a <form> with an ID attribute that starts with QLf, because it looks like the numbers after, are automatically generated.