Skip to content
Advertisement

How to solve “selenium.common.exceptions.NoSuchElementExceptio” in selenium when creating a twitter bot?

I am trying to creating a twitter bot and I am stuck on the log in page.
Here is my code:

JavaScript

I am always getting the the below mentioned error:

JavaScript

I have tried it with css_selector, xpath, class, ID but nothing seems to work. I am not able to click the box to enter my email ID and password.

Can some one please show me how to solve this error.

Advertisement

Answer

There are several problems with your code:

  1. You need to wait for element to be clickable before accessing it. The best way to do that is to use WebDriverWait expected_conditions explicit waits.
  2. You should never use absolute paths as a locators. These locators are extremely breakable. Short unique locators should be used instead.
  3. The element you trying to click is not the element should be clicked there.

The following code works:

JavaScript

The result is

enter image description here

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