selenium TimeoutException: in automating whatsap - python-3.x

i am automating whatsap by using selenium and python script. I am trying to open chat by using xpath.it works well with recent chats, but when i try to open chat from contacts it raises TimeoutException.
here is my code:
import traceback
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
import time
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.wait import WebDriverWait
chrome_browser = webdriver.Chrome(executable_path = 'F:\driver\chromedriver.exe')
chrome_browser.get('https://web.whatsapp.com/')
time.sleep(15)
#print('scanning is completed')
wait = WebDriverWait(chrome_browser , 30)
user_name = "sakshi clg"
#user = chrome_browser.find_element_by_xpath('//span[#title="{}"]'.format(user_name))
#user.click()
#visibility_of_element_located element_to_be_clickable
#wait.until(EC.element_to_be_clickable(By.XPATH , "//span[#title=User_name]"))
try:
user=wait.until(EC.presence_of_element_located((By.XPATH ,"//span[#title='{}']".format(user_name))))
user.click()
except TimeoutException:
traceback.print_exc()
exception details:
Traceback (most recent call last):
File "C:/Users/DELL/PycharmProjects/whatsap_prj/main.py", line 25, in
user=wait.until(EC.presence_of_element_located((By.XPATH ,"//span[#title='{}']".format(user_name))))
File "C:\Users\DELL\PycharmProjects\whatsap_prj\venv\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
please someone help me.I am new to selenium.

Related

How to iterate over webelement

Hi i have this code which takes text from this element
but because its web element i cant append it to list or loop over it how i can do this.
here is my code
import selenium
import os
from tkinter import *
from tkinter import filedialog
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium import webdriver
from selenium import webdriver
import contextlib as textmanager
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
PATH= "C:\chromedrivers\chromedriver.exe"
driver= webdriver.Chrome(PATH)
driver.get("https://typetest.io/")
textt= driver.find_element_by_class_name("test-word")
for items in textt:
print(items.text)
here is the output
Traceback (most recent call last):
File "c:\Users\ramhelsinki\projects\selenium typtest.io .py", line 26, in <module>
for items in textt:
TypeError: 'WebElement' object is not iterable
Use elements instead of element like this -
textt = driver.find_elements_by_class_name("test-word")

Bluetooth error while making gmail login bot using selenium in python. But even the basic search for "Email" id element is also not found

It does not seem to work and keeps giving me an error regarding Bluetooth drivers
Following is my code:-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
usernameStr = 'putYourUsernameHere'
passwordStr = 'putYourPasswordHere'
browser = webdriver.Chrome()
browser.get(('https://accounts.google.com/ServiceLogin?'
'service=mail&continue=https://mail.google'
'.com/mail/#identifier'))
# fill in username and hit the next button
username = browser.find_element_by_id('Email')
username.send_keys(usernameStr)
nextButton = browser.find_element_by_id('next')
nextButton.click()
# wait for transition then continue to fill items
password = WebDriverWait(browser, 10).until(
EC.presence_of_element_located((By.ID, "Passwd")))
password.send_keys(passwordStr)
signInButton = browser.find_element_by_id('signIn')
signInButton.click()
This is the error of my code:-
[11092:17164:0603/171812.746:ERROR:device_event_log_impl.cc(208)] [17:18:12.747] Bluetooth: bluetooth_adapter_winrt.cc:723 GetBluetoothAdapterStaticsActivationFactory failed: Class not registered (0x80040154)
Traceback (most recent call last):
File "e:/python.py", line 62, in
username = browser.find_element_by_id('Email')
File "C:\Users\Bhaskar\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\Bhaskar\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
'value': value})['value']
File "C:\Users\Bhaskar\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\Bhaskar\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":"css selector","selector":"[id="Email"]"}
(Session info: chrome=83.0.4103.61)
The username box doesn't have the id 'Email', but 'identifierId'. The same goes for the 'next' button.
Try something like this (might work a bit different for you, since I have Google in a different language).
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
usernameStr = 'putYourUsernameHere'
passwordStr = 'putYourPasswordHere'
browser = webdriver.Chrome()
browser.get(('https://accounts.google.com/ServiceLogin?'
'service=mail&continue=https://mail.google'
'.com/mail/#identifier'))
# fill in username and hit the next button
username = browser.find_element_by_id('identifierId')
username.send_keys(usernameStr)
nextButton = browser.find_element_by_xpath('//*[#id="identifierNext"]/span/span')
nextButton.click()
After this, Google blocks my attempts...
ID you are looking for is "identifierId". try with that.

Selenium not finding element by xpath, id, class etc. Tried explicit wait

I am trying to write a script that automates our reporting.
I am attempting to find the username element with selenium but it is not finding it by class, xpath, id etc.
I have tried implementing an explicit wait but to no avail.
I am incredibly new to the world of python so apologies for stupid errors.
Here is what I have:
`from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
chromedriver = r"C:\Users\LouisKempson\Desktop\chromedriver"
driver = webdriver.Chrome(chromedriver)
driver.get("http://ba-app02:8080/InfoViewApp/logon.jsp")
wait = WebDriverWait(driver, 3)
username = wait.until(EC.presence_of_element_located((By.ID, "usernameTextEdit")))
username.send_keys('opsteams')`
error is :
Traceback (most recent call last):
File "C:/Users/LouisKempson/PycharmProjects/Test/venv/Lib/Sign_In_Firefox.py", line 9, in <module>
username = wait.until(EC.presence_of_element_located((By.ID, "usernameTextEdit")))
File "C:\Users\LouisKempson\PycharmProjects\Test\venv\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Many thanks for your help
Please try below solution
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
chromedriver = r"C:\Users\LouisKempson\Desktop\chromedriver"
driver = webdriver.Chrome(chromedriver)
driver.get("http://ba-app02:8080/InfoViewApp/logon.jsp")
wait = WebDriverWait(driver, 10)
inputElement = driver.find_element_by_name("username")
inputElement.send_keys("opsteams")

Python Selenium error - is not clickable at point (207.1666717529297,25) because another element <div id="overley" class="over_ley"> obscures it

I have below code -
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("url")
username = driver.find_element_by_id("LoginID")
pwd = driver.find_element_by_id("Password")
username.send_keys('usrnme')
pwd.send_keys('pswd')
Login = driver.find_element_by_id("Button2")
Login.click()
Create = driver.find_element_by_xpath("//*[#title='Create Incident']")
Create.click()
Whenever I am running this code in script or in batch I am getting below error -
Traceback (most recent call last):
File "P:\Selenium\helpline1.py", line 15, in <module>
Create.click()
File "P:\Selenium\python-3.5.1\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "P:\Selenium\python-3.5.1\lib\site-packages\selenium\webdriver\remote\webelement.py", line 628, in _execute
return self._parent.execute(command, params)
File "P:\Selenium\python-3.5.1\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "P:\Selenium\python-3.5.1\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 237, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: Element <a id="anc" class="RedirectTab" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("anc", "", true, "", "", false, true))"> is not clickable at point (207.1666717529297,25) because another element <div id="overley" class="over_ley"> obscures it
Login to the site happens perfectly but after that this error in clicking an element (that is the next line of code).
Also when I am running this code line by line manually in Python IDLE or Python CLI it runs without any error. Issue just in script/batch mode in IDLE or Python CLI
Thanks to suggest.
If overlay displayed while you're trying to perform a click, you might need to wait until overlay is closed:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
...
Create = driver.find_element_by_xpath("//*[#title='Create Incident']")
WebDriverWait(driver, 10).until_not(EC.visibility_of_element_located((By.ID, "overley")))
Create.click()
Try this:
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
wait = WebDriverWait(driver, 10)
driver.get("url")
username = driver.find_element_by_id("LoginID")
pwd = driver.find_element_by_id("Password")
username.send_keys('usrnme')
pwd.send_keys('pswd')
Login = driver.find_element_by_id("Button2")
Login.click()
element = wait.until(EC.element_to_be_clickable((By.XPath, "//*[#title='Create Incident']")))
Create = driver.find_element_by_xpath("//*[#title='Create Incident']")
Create.click()
By usin a wait, you will give time to browser to load de button, BEFORE try to performe the click, that will happen when the element is prepared.

selenium webdriver chrome- "bound method Service"

I am trying to pass an url and get the data using beautifulsoup, but i am resulting in the following error. i dont have any clue what this error is about. i have read some stackoverflow questions but i am unable to find a perfect solution. Please help me. Below is the code and the error.
from selenium import webdriver
import os, time, csv, datetime
from selenium.webdriver.common.keys import Keys
import threading
import multiprocessing
from selenium.webdriver.support.select import Select
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
import openpyxl
from bs4 import BeautifulSoup
import urllib.request
import pandas as pd
driver = webdriver.Chrome()
url = "https://abcdefgh.com"
page = urllib.request.urlopen(url).read()
soup = BeautifulSoup(page, "html5lib")
a = soup.find_all("table", class_="readonlydisplaytable")
for b in a:
c = b.find_all("tr", class_="readonlydisplayfield")
for d in c:
if "Super#" in d.get_text():
e = d.find("td", class_="readonlydisplayfielddata")
print(e.get_text())
Error:
C:\Users\mpk\AppData\Local\Programs\Python\Python36-32\python.exe C:/Users/mpk/Documents/Python/excel.py
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.chrome.service.Service object at 0x004BB330>>
Traceback (most recent call last):
File "C:\Users\mpk\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 173, in __del__
File "C:\Users\mpk\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 149, in stop
File "C:\Users\mpk\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 120, in send_remote_shutdown_command
ImportError: sys.meta_path is None, Python is likely shutting down
Process finished with exit code 0
I had a similar problem when running selenium in an AWS lambda server. I am not really sure why it throws the error because on my laptop it works fine, it's just running it in the server that is the problem. It might be something to do with the program terminating with the webdriver still going.
The following solved the problem for me:
At the end of your script before the program terminates, write:
driver.quit()
This closes the browser and as I say, fixed it for me. Hope it works for you too!

Resources