can't click button with selenium python - python

i can't find way to press button with selenium. tried to click on it by name and xpath, but it didnt worked.
this is sign in button on this site - https://account.envato.com/sign_in?to=audiojungle
this is code of button:
<input type="submit" name="commit" value="Sign in to your account" class="js-sign-in__submit e-btn--3d -color-primary -size-m -width-full h-mb2 h-mt1">
if i try to find it by x path, using - driver.find_element_by_xpath('//*[#id="sign-in-form"]/div[6]/input').click()
or using - driver.find_element_by_name('commit').click()
it comes with this problem -
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <input type="submit" name="commit" value="Sign In"formnovalidate="formnovalidate" data-disable-with="Sign In"> is not clickable at point (789, 309). Other element would receive the click: <p style="">...</p>
i don't remember evrything i tried, but i hope you understood me. i didn't find solution in internet, so i hope you will help me, thx)

Try this:
Option 1:
wait.until(ec.visibility_of_element_located((By.XPATH,"Your xpath")
Option 2:
Check if it is not in iframe.
Option 3:
Use Action or Javascript to click on button.
Hope this helps.

Related

Selenium Python Checkbox Click

I am trying to access the following HTML checkbox for a button click:
<input type="checkbox" data-ng-value="sf.name" data-ng-model="sf.checked" ng-click="ec.onStateFilterChanged(sf)" title="Select a state" class="ng-untouched ng-valid ng-dirty ng-valid-parse" value="Arizona">
using:
state = driver.find_element_by_xpath("input[#type='checkbox']").click()
but keep getting error:
selenium.common.exceptions.NoSuchElementException: Message:
what might be the element path I am looking for in order to select the checkbox?
Your xpath is most likely incorrect - you need to enter // before the element as this will find all (single slash / will work here too though as you are only trying to find one element and it will find the first match)
Try one of the following:
state = driver.find_element_by_xpath("//input[#type='checkbox']").click()
OR
state = driver.find_element_by_css_selector("input[type='checkbox']").click()

Clicking the hidden input Selenium in Python

I am trying to automate the login procedure with Selenium in Firefox with Python.
That's how a login button looks like in HTML:
<td>
<input name="cmd" value="lg" type="hidden">
<input src="ok.png" style="border-style: none;" type="image">
</td>
I have tried a following method:
loginButton = driver.find_elements_by_xpath("//input[#name='cmd' and #value='lg']")[0]
loginButton.click()
It returns the following exception with an empty message.
"selenium.common.exceptions.ElementNotInteractableException: Message: "
This method returns
"Message: Element is not visible"
loginButton = driver.find_element_by_name("cmd")
loginButton.send_keys(Keys.RETURN)
Could you please explain what I am missing?
If you want to click on input next to hidden, try
loginButton = driver.find_element_by_xpath("//input[#src='ok.png']")
# loginButton = driver.find_element_by_xpath("//input[#name='cmd' and #value='lg']/following-sibling::input")
loginButton.click()

submit element not clickable selenium python

I was trying to open stackoverflow and search for a query and then click the search button.
almost everything went fine except I was not able to click submit button
I encountered error
WebDriverException: unknown error: Element ... is not clickable at point (608, 31). Other element would
receive the click: (Session info:
chrome=60.0.3112.101) (Driver info: chromedriver=2.29.461591
(62ebf098771772160f391d75e589dc567915b233),platform=Windows NT
6.1.7601 SP1 x86)
browser=webdriver.Chrome()
browser.get("https://stackoverflow.com/questions/19035186/how-to-select-element-with-selenium-python-xpath")
z=browser.find_element_by_css_selector(".f-input.js-search-field")#use .for class and replace space with .
z.send_keys("geckodriver not working")
submi=browser.find_element_by_css_selector(".svg-icon.iconSearch")
submi.click()
<button type="submit" class="btn js-search-submit">
<svg role="icon" class="svg-icon iconSearch" width="18" height="18" viewBox="0 0 18 18">
<path d="..."></path>
</svg>
</button>
You are trying to click on the svg. That icon is not clickable, but the button is.
So change the button selector to .btn.js-search-submit will work.
Use below code to click on submit button:
browser.find_element_by_css_selector(".btn.js-search-submit").click()
Click the element with right locator, your button locator is wrong. Other code is looking good
try this
browser=webdriver.Chrome()
browser.get("https://stackoverflow.com/questions/19035186/how-to-select-element-with-selenium-python-xpath")
z=browser.find_element_by_css_selector(".f-input.js-search-field")#use .for class and replace space with .
z.send_keys("geckodriver not working")
submi=browser.find_element_by_css_selector(".btn.js-search-submit")
submi.click()

Clicking on an image in selenium

I'm having an issue clicking on an image using the Chromedriver with Selenium for the following HTML:
<div class="modal_buttons">
<input type="image" name="GoButton" id="GoButton" tabindex=14 title="Continue" alt="Continue" onfocus="SetLastFocus(this.id)" src="https://t4.ftcdn.net/jpg/00/81/83/05/240_F_81830511_aJbF2vH9yufF0UAUFQ83JDnbp0jE5mNV.jpg"
I tried using the following code:
element = driver.find_element_by_css_selector("//div[img/#src='https://t4.ftcdn.net/jpg/00/81/83/05/240_F_81830511_aJbF2vH9yufF0UAUFQ83JDnbp0jE5mNV.jpg']").click()
Selenium is failing everytime, and giving the same list of errors that it can't locate the button. Any ideas how to fix?
Thanks
Try:
driver.find_element_by_xpath("//input[#id='GoButton'][#name='GoButton']").click()
or
driver.find_element_by_xpath("//input[#id='GoButton'][#title='Continue']").click()
or
driver.find_element_by_xpath("//input[#name='GoButton'][#title='Continue']").click()
or
driver.find_element_by_xpath("//input[contains(#src,'240_F_81830511_aJbF2vH9yufF0UAUFQ83JDnbp0jE5mNV.jpg')]")

Canot click button with Python with Selenium

I am trying to click a button that brings up a dialogue box to select a file. inspecting the element it looks like its an input rather than a button. Either way I cannot click it with:
element = browser.find_element_by_id("fileupload")
element.click()
and
browser.find_element_by_id("fileupload").send_keys("\n")
Neither of which seem to work.
Here is what I see when I inspect that element on the page:
<span class="btn btn-success fileinput-button">
<span class="glyphicon glyphicon-upload"></span>
Select and Upload...
<input id="fileupload" name="upfile" accept=".xml" type="file">
</span>
Any assistance help or pointers would be appreciated!
Clicking on a file input usually triggers a file upload dialog. Since you cannot control it with selenium, you need to avoid the dialog being opened by sending keys to the input instead:
browser.find_element_by_id("fileupload").send_keys("path_to_the_file")
See also:
How to deal with file uploading in test automation using selenium or webdriver
How to upload file using Selenium WebDriver in Java
How to upload file ( picture ) with selenium, python

Categories