Rob
Rob

Reputation: 37

Python Selenium - Automate filling forms - Click on a button that is not a submit button and filling in a form from a list

I try to automate filling a CMS with an Excel sheet. In my CMS, I want to link a tag to my ID object. Tags are a list to pick from. So my Excel table is basically 2 columns (ID and tags)

Everything works well so far except for one button. This button links a tag to its object, it's not a submit button but a typeless button.

<button class="btn btn-info link_tag">Link</button>

Here is a part of the code:

# fill in the 'tag' form
driver.find_element_by_name('Tag').send_keys('tag_name')
# link the tag with the ID
driver.find_element_by_xpath('//*[@id="form1"]/fieldset[2]/div/div[2]/div/div/div/div[2]//*[@class="btn btn-info link_tag"]').click()

First I fill in this field and dropdown list of suggestions will come out

Example for Google:

Example for Google

However, after this, my button "Link", which should link the tag, does not work. I do not have any error message, it just doesn't do anything. The button is not a submit type, so I figured the problem comes from that? Or maybe the problem comes from the fact that the tag form is a search form (it will show suggestions)?

Also to note on the web browser that selenium opens, I cannot click on the button myself with my mouse neither. I click on it but nothing happens. I have to re-write the tag to be able to link my tag to my ID. However, if I select the option from the dropdown list, then I can click on the button.

Below that, there's a submit button ("Save") that works but since the tag is not linked with the ID, it doesn't have anything to save.

If done by a human, it is possible to link the tag either by pressing ENTER or click on this "Link" button or the Tab key

I tried to use send_keys(u'\ue007'), send_keys(Keys.ENTER), send_keys(Keys.TAB), click(), time.wait to wait out the page but none of these solutions worked (on both the filling field and the link button).

Is there any idea on how to solve this?

Upvotes: 1

Views: 248

Answers (1)

Rob
Rob

Reputation: 37

Update, I found the solution, which is actually pretty stupid..

# fill in the 'tag' form
tag = driver.find_element_by_name('Tag') 
tag.send_keys('tag_name')
tag.send_keys(u'\ue007')
# link the tag with the ID
driver.find_element_by_xpath('//*[@id="form1"]/fieldset[2]/div/div[2]/div/div/div/div[2]//*[@class="btn btn-info link_tag"]').send_keys("\n")

This worked for me. I needed to find a way to "validate" the option in the dropdown list so pressing the key enter was what solved it for me.

Also, the button "Submit/Save" did not work properly, so I tried to do a wait a few seconds (it worked), but it is not an ideal solution. However adding send_key("\n") worked for me.

Upvotes: 1

Related Questions