Submit button is not working in Python Selenium - python

I don't have experience in Selenium. I have tried a couple of things to click a submit button inside a form but nothing is working for me. Please help me out to solve this problem.
I found that the button is enabled (is_enabled()), but not displayed (is_displayed()).
I tried the following options one by one. I have added the consecutive result of that code in the comment.
z=driver.find_element_by_xpath("//input[#name='commit']")
z.click() #It is showing error, Message: element not interactable
z.send_keys(Keys.ENTER) #It is showing error, Message: element not interactable
driver.execute_script("arguments[0].click();", z) #Shows no error, but nothing happens
z.submit() #Shows no error, but nothing happens
I tried with driver.implicitly_wait(20) but no luck.
I tried with until option too but it gives error.
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[#name='commit']"))).submit() #This raises TimeoutException
The HTML code is following
input type="submit" name="commit" value="Calculate" class="btn btn-primary" autocomplete="off" data-disable-with="Calculate"
The webpage link is : https://proteins.plus/ktypdbdd9c38b7-1738-45fd-a0fb-90ea86f5dd8b
I clicked on "DoGSiteScorer Binding site detection", then "DoGSiteScorer" button. Now I want to lick the "Calculate" button which is not working.
How should I do it then?

The problem is this:
z=driver.find_element_by_xpath("//input[#name='commit']")
returns 11 elements on that page, and you can't call click() on 11 elements.
Assuming you want to click the red Calculate button, try this:
z = driver.find_element_by_xpath("(//input[#name='commit'])[2]")
z.click()

Related

No response after clicking element (Python Selenium )

I am working on 3 webpages (Let say Page A to C) with Python Selenium.
Both Page A and B contain this button:
<button id="continue-button" type="button" class="form-button" data-autom="button-label"><span>Click</span></button>
When clicking this button on Page A, it will jump to Page B; When clicking it on Page B, it will jump to Page C
I use the following code to perform auto click action on Page A, it works great.
element_confirm = driver.find_element("id", 'continue-button')
driver.implicitly_wait(5)
driver.execute_script("arguments[0].click();", element_confirm)
However, when I execute above code (different element name) again on Page B, nothing is happened.
No error message is on the log. I tried to print some text after driver.execute_script. It shows normally. I tried to find the element with "xpath", '//*[#data-autom="button-label"]', also no clcik action is performed. Checked the element is True (It means it can be found).
100% confirm that Page A to C are working fine when I click the button manually (using my mouse). Any recommendation?
Thank you!
Update:
As requested, this is the code that I use for Page B:
element_submit_two = driver.find_element(By.ID, 'continue-button')
driver.implicitly_wait(5)
driver.execute_script("arguments[0].click();", element_submit_two)
Aren't you using outdated selenium? According to docs, you should use like that:
from selenium.webdriver.common.by import By
button = driver.find_element(By.ID, "continue-button")
button.click()

Unable to Click on Dropdown using Python Selenium

I'm trying to select an element from a dropdown but getting an error.
Here is the HTML:
<select id="childContextDDL" data-filter="contains" data-role="dropdownlist" data-template="dcf-context-picker" data-value-field="Value" data-text-field="DisplayText" data-bind="events: { change: childContextListChange }, source: childContextList.ChildContextList" style="display: none;">
<option value="1">NATION</option>
<option value="12">ATLANTIC</option>
<option value="16">CHARLOTTE, NC</option>
And this is the code that I'm trying to run:
mySelect = Select(driver.find_element_by_id("childContextDDL"))
print('MySelect is: ',mySelect)
mySelect.select_by_visible_text('ATLANTIC')
I'm getting this error:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: Element is not currently visible and may not be manipulated
What's the possible reason for getting this error? I'm very new to Selenium.
I also want to click on that element after selecting it.
The problem was that the style within the html was set to none. So I had to first change that style to block to make it visible and then proceed with the clicking operation.
Here's the code that worked:
driver.execute_script("document.getElementById('childContextDDL').style.display = 'block';")
mySelect = Select(driver.find_element_by_id("childContextDDL"))
print('MySelect is: ',mySelect)
mySelect.select_by_visible_text('ATLANTIC')
randomClick = driver.find_element_by_id('dcf-user-info')
randomClick.click()
I guess the mySelect element (the dropdown menu) is not visible.
So please try the following:
from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(driver)
mySelect = Select(driver.find_element_by_id("childContextDDL"))
actions.move_to_element(mySelect).perform()
mySelect.select_by_visible_text('ATLANTIC')
If the above doesn't work (I can't see the actual site you are working on), the following can work instead in the element has to be tapped to become enabled
action = TouchActions(driver)
action.tap(mySelect).perform()
mySelect.select_by_visible_text('ATLANTIC')
If it says it is not currently visible, you should try pausing the code with one of this options:
time.sleep(1) #This states to your code to stop for 1 second and the continue with the work.
WebDriverWait(driver, 10).until(EC.element_to_be_visible(BY.value, "12")) # tells the driver to wait a maximum of ten seconds until the value "12" is visible for the driver.

Scroll to view in filling web form error using pyAutoGUI in Python

I have this code to fill a web form:
driver.find_element_by_id("author").click() # This opens the windows file selector
pyautogui.write('John')
pyautogui.press('enter')
but if gives me an error:
selenium.common.exceptions.ElementNotInteractableException: Message: Element <select id="author" class="select2-authors-multiple select2-hidden-accessible" name="author[]"> could not be scrolled into view
how can i resolve this? i have tried some code but it did not work like:
driver.execute_script("arguments[0].scrollIntoView();", element)
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
Thread.sleep(500);
Because you are using pyautogui try to instead of scroll, to navigate with the arrows down like this pyautogui.press("down")

Python selenium can't click a button execute script

I am trying to click a button from the Linkedin public page feed
https://www.linkedin.com/company/bbc-news/
and the button is a post's toolbar button with 3 dots
here is the sample screenshot
and my code is
self.browser.execute_script("document.getElementsByClassName('feed-shared-control-menu__trigger artdeco-button artdeco-button--tertiary artdeco-button--muted artdeco-button--1 artdeco-button--circle artdeco-dropdown__trigger artdeco-dropdown__trigger--placement-bottom ember-view')[1].scrollIntoView();")
self.browser.execute_script("document.getElementsByClassName('feed-shared-control-menu__trigger artdeco-button artdeco-button--tertiary artdeco-button--muted artdeco-button--1 artdeco-button--circle artdeco-dropdown__trigger artdeco-dropdown__trigger--placement-bottom ember-view')[1].click();")
it doesn't return any errors
please kindly help me solve this issue
Thanks in advance for any help
Note: I have already tried webDriverwait , find_elements_by_class_name
The element has an id associated to it, so you can use that id to get the xpath of the element and then you can click it. Also, it is recommended to use the selenium click instead of the javascript executor click(which you are currently using).
Your code should be like:
self.browser.find_element_by_xpath("//button[#id='ember160']//li-icon").click()
If you want to use javascript executor click, then your code should be like:
element = self.browser.find_element_by_xpath("//button[#id='ember160']//li-icon")
driver.execute_script("arguments[0].click();", element)

Element is not clickable (the button is blocking by other element)

I'm trying to click on this button: browser.find_element_by_id('btnSearch')
But this button is blocking by this div tag: <div id="actionSearch" class="row pull-right">
How do I go around to click this button with id='btnSearch" while it's blocking by the actionSearch div?
I tried the following:
browser.find_element_by_id('btnSearch').click()
browser.implicitly_wait(10)
el = browser.find_element_by_xpath('//*[#id="btnSearch"]')
ActionChains(browser).move_to_element_with_offset(el, 1827, 270)
ActionChains(browser).click()
ActionChains(browser).perform()
element = browser.find_element_by_id('btnSearch')
browser.execute_script("arguments[0].click();", element)
wait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, //*[#id="btnSearch"]'))).click()
none of these work.
Can anyone help me with this? I've spent two days trying to click this button!! Please help!
Considering provided image of HTML source (tip: do not provide it as image, but as text instead) I can assume that required element located in the bottom of page and you might need to scroll page down to be able to handle it.
Try below code
link = browser.find_element_by_id("btnSearch")
browser.execute_script("arguments[0].scrollIntoView()", link)
link.click()
Note that link is not a pseudo-element (is not located inside ::before/::after pseudo-element), so it can not be the cause of your problem
As for your code:
ActionChains(browser).move_to_element_with_offset(el, 1827, 270)
ActionChains(browser).click()
ActionChains(browser).perform()
Here you're trying to make scroll to link with huge offset and then you make click on current mouse position - not on link
You can try to modify it as
ActionChains(browser).move_to_element(el)
ActionChains(browser).click(el) # Pass WebElement you want to click as argument to `click()`
ActionChains(browser).perform()

Categories

Resources