Skip to content
Advertisement

WhatsApp Web Automation with Python Selenium (unable to locate element)

I am using python and selenium to send a message to a target.

I can successfully open whatsapp web but after that I cannot open the inbox of the contact to whom I want to send the message.

Here is the code so far. The first part is common where I have to open the web page. It happened without any problem. The next part is to open the contact to send the inbox message. I tried two different methods for it. Neither of them worked.

Common Part:

JavaScript

Method 1:

JavaScript

Image of HTML code.

It gives error:

JavaScript

Method 2: This method is copied from one of a solution from Stack OverFlow.

JavaScript

It gives error:

JavaScript

It’s been more than a month now and I cannot solve the problem.

Please do not close the question saying it is already asked. I know there are tons of questions on this topic but neither of them worked for me and it would be great help if you would give me the solution specific to my problem.

Thanking you in advance.

Advertisement

Answer

Finally, I got the answer.

I realize there is no point in opening the search box. Typing name in the search box only brings the name appear on top, it cannot select any of the contacts.

We should find the name of the contact from the center-left side of the screen.

For that use:

JavaScript

It opens the inbox.

The link to complete project is here: https://github.com/AshTiwari/WhatsApp-Automation-using-selenium-and-Python Please give a star as it will really encourage me.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement