Force click highlights button but doesn't click it? - Python selenium - python

I am attempting to click on a button.
element.click() was not consistently clicking, so I tried to force a click driver.execute_script("arguments[0].click();", element). However, my force click doesn't click the button, but only highlights the borders of the button.
I suspected that perhaps the button was a dynamic element. But I tried accounting for that in my xpath.element.click() isn't consistent enough to use, but force click doesn't seem to be doing the trick.
I couldn't find any information about why a force click might not work, besides a dynamic element. Any ideas what might be going on?
driver.get("https://bi.prozorro.org/sense/app/fba3f2f2-cf55-40a0-a79f-b74f5ce947c2/sheet/HbXjQep/state/analysis")
element=WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, "//th[#tid='st.header']//span[#title='Учасник']//following::th[#tid='st.header.search']")))
#element.click()
driver.execute_script("arguments[0].click();", element)

Related

How to avoid ElementClickInterceptedException when working with Selenium?

I use selenium with python and want to mark a checkbox by clicking on it.
After having identified the <input> tag of the checkbox with selenium, I attempt to click on it with
checkbox.click()
However, it throws the ElementClickInterceptedException.
I identify the checkbox I want to click on through a loop. When I try to click on the checkbox outside of the loop (by manually running the code after it was identified and saved to a variable), I found two things:
All things equal, I still get the exception
When I click in the browser window once (that was opened with selenium) and then run checkbox.click(), it works as expected
Any ideas why and how I could attempt to slove this issue (i.e. being able to click on the checkbox within the loop)?
Thanks!
You either deal with the overlapping element or use javascript
driver.execute_script("arguments[0].click();", checkbox)
Sometimes, the checkbox is not directly interactable. You may have to click on the label/text next to the checkbox.
or May be you have to wait till the element is clickable since your are running in a loop.

Why in Selenium the command driver.find_element_by_xpath doesn't work?

I'm trying to find and click an element with this command:
driver.find_element_by_xpath('//*[#id="address-book-entry-0"]/div[2]').click()
But it doesn't work.
For other buttons it's working, why for this it is not working?
Can you help me please?
You should show the relevant part of the HTML in order to be sure, but this behaviour could be caused by:
Wrong XPath.
The element is not clickable. You can wait until it is clickable. Check again that there is no other element on top of yours that will receive the click.
The element is in iframe. Switch to the iframe first.
If the suggestions above are not working for you, try to click the button with JavaScript.

Selenium - Scroll and click

I would like to know if there is any way to scroll down and also click on buttons at the same time.
For example Instagram. When you click on account 'follow' there is a pop up with images, text, and buttons.
There is any way to scroll and mean time to do other stuff?
For example, scroll down and click on the 'Follow' button while it's scrolling down.
Now I'm just using this code driver.execute_script("""arguments[0].scrollTo(0, arguments[0].scrollHeight); return arguments[0].scrollHeight;""", element)
Which is good, BUT it first scrolls all the way down, and when it finishes then I can do whatever I want to. Which is not the solution I'm looking for.
Any tips guys?
I'm using Chrome driver

Unable to highlight text after selenium webdriver click()

I am using python code such as below to click an element within an iframe on an angularjs page.
browser = webdriver.Ie()
browser.switch_to.frame('name')
browser.find_element_by_id('value').click()
After using click() I am unable to manually highlight text that appears on the page. Why might this happen? How can I restore the ability to highlight text with the mouse?
I have tried switching back to default content, but this makes no difference. Any ideas?
Other strange effects after using click(): Links and buttons don't work while using the mouse manually unless double-clicked. These would normally require single click. It is as if there is an invisible overlay blocking text selection or clicking links. Radio buttons and menus still work.
Edit: The site uses silverlight and I am wondering if this is related to the problem that results from using click().

Selenium WebDriver python: checkbox cannot click, default the checkbox is invisible and when hover it can be visible

all
I am now testing Onedrive(onedrive.live.com)and want to simulate the checkbox as following screenshot:
(I am a new comer and cannot post image due to need at least 10 reputation. Sorry! )
In default the checkbox is invisible, when mouse hover the file and it will be visible, and click it. I use Selenium to simulate the whole action but fails, and some code snippet shows below:
elem1=driver.find_elements_by_xpath('//div[#class="c-SetItemTile "]')
hover=ActionChains(driver).move_to_element(elem1[6])
hover.perform()
driver.implicitly_wait(3)
elem2=elem1[6].find_element_by_tag_name("input")
#WebDriverWait(driver,60).until(lambda driver : elem2.is_displayed())
print elem2.tag_name
print elem2.get_attribute("id")
if elem2.is_displayed():
elem2.click()
else:
print "not checked!!!"
Note: when I use WebDriverWait for waiting the checkbox is visible, but it seems that it always is invisible.
Anyone help me? Thanks
If there is a find by class option in Selenium(I know there is one in splinter) then try doing find_element_by_class_name("selectArea") (or whatever you would use in Selenium to find elements on a page) The box just checks your cursors position and if that is in the select area and you click it will count that as checked. I hope that makes sense.

Categories

Resources