Web page behaves differently if I type text in input box than I use webdriver to send Keys in selenium

Viewed 70

I am new to selenium and trying to automate a WordPress social media schedule plugin. The problem is there is a link text box as shown below. Url text box

Now if I type URL in this box and click continue it I will get the next page like this : next Page after writing url

But when I try to automate this step using this code :

mydriver = webdriver.Chrome(Path)
cookies = get_cookies_values("cookies.csv")
mydriver.get(url)
for i in cookies:
    mydriver.add_cookie(i)
mydriver.get(url)
link_element = WebDriverWait(mydriver, 10).until(
    EC.presence_of_element_located((By.ID, "b2s-curation-input-url"))
)

link_element.send_keys(link)

mydriver.find_element_by_xpath('//*[@id="b2s-curation-post- 
    form"]/div[2]/div[1]/div/div/div[2]/button').click()

Now, if I run the above code, which gets the URL, it also loads my cookies, but when it clicks on the continue button after sending keys, I get this type of page with an extra field with the name of the title. I don't want this extra title box as shown in the picture below extra field next page

I would like to know what is causing this issue. I am using python 3.8 with Chrome web driver version 92.0.4515.131. Thank you

1 Answers

One possibility is to try entering the URL character-by-character, as opposed to sending the entire string. The former is closer to the process of manually typing in the link, and assuming the site has a Javascript listener to catch the input, a character-by-character input process will be intercepted differently than a copy-paste of the entire URL:

mydriver = webdriver.Chrome(Path)
cookies = get_cookies_values("cookies.csv")
mydriver.get(url)
for i in cookies:
    mydriver.add_cookie(i)
mydriver.get(url)
link_element = WebDriverWait(mydriver, 10).until(
    EC.presence_of_element_located((By.ID, "b2s-curation-input-url"))
)
for c in link: #send each character to the field
   link_element.send_keys(c)
   #import time; time.sleep(0.3) => you could also add a short delay between each entry

mydriver.find_element_by_xpath('//*[@id="b2s-curation-post- 
    form"]/div[2]/div[1]/div/div/div[2]/button').click()
Related