0

I want to log in to tik tok using selenium, but the typical selenium doesn't work there. Tik tok website is just detecting my selenium browser. Does anyone has any idea how to bypass that?

I'm currently trying with undetectable chromedriver but my problem is that it doesn't find ANY elements. Like my usual code with selenium is working but when I'm using "undetectable chromedriver" it can't find literally any element. How to fix that?

driver = uc.Chrome(use_subprocess=True)
driver.get("https://www.tiktok.com/signup/phone-or-email/email")
time.sleep(3)

def logging_in():
    #email
    try:
        element = driver.find_element("xpath","//input[@placeholder='Email address']")
        element.send_keys("aasd")
    except:
        print("")
logging_in()

Error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@placeholder='Email address']"} (Session info: chrome=104.0.5112.102) Stacktrace: Backtrace: Ordinal0 [0x006E78B3+2193587] Ordinal0 [0x00680681+1771137] Ordinal0 [0x005941A8+803240] Ordinal0 [0x005C24A0+992416] Ordinal0 [0x005C273B+993083] Ordinal0 [0x005EF7C2+1177538] Ordinal0 [0x005DD7F4+1103860] Ordinal0 [0x005EDAE2+1170146] Ordinal0 [0x005DD5C6+1103302] Ordinal0 [0x005B77E0+948192] Ordinal0 [0x005B86E6+952038] GetHandleVerifier [0x00990CB2+2738370] GetHandleVerifier [0x009821B8+2678216] GetHandleVerifier [0x007717AA+512954] GetHandleVerifier [0x00770856+509030] Ordinal0 [0x0068743B+1799227] Ordinal0 [0x0068BB68+1817448] Ordinal0 [0x0068BC55+1817685] Ordinal0 [0x00695230+1856048] BaseThreadInitThunk [0x75EB6739+25] RtlGetFullPathName_UEx [0x76FB90AF+1215] RtlGetFullPathName_UEx [0x76FB907D+1165]
David Scholz
  • 8,421
  • 12
  • 19
  • 34
zinkq
  • 1
  • 1

1 Answers1

0

The locator strategy you have used, i.e.

driver.find_element("xpath","//input[@placeholder='Email address']")

was perfect was perfect as it uniquely identifies the Email address field on Tiktok Login Page.

tiktok_email


Solution

Ideally, to send a character sequence to the <input> element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    driver.get('https://www.tiktok.com/signup/phone-or-email/email')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[placeholder='Email address']"))).send_keys("zinkq@stackoverflow.com")
    
  • Using XPATH:

    driver.get('https://www.tiktok.com/signup/phone-or-email/email')  
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@placeholder='Email address']"))).send_keys("zinkq@stackoverflow.com")
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352