Click method on Selenium 2.40.2 does not work - python-3.x

I am using Selenium 2.40.2 for testing web application. I need the mouse move and click to draw a polygon on the google map.
The code is below:
bottom_label = browser_drive.find_element_by_xpath("//span[text()='Project']")
time.sleep(2)
drawing = ActionChains(browser_drive)\
.move_to_element(bottom_label)\
.move_by_offset(-650, -600)\
.click()\
.move_by_offset(100, -100)\
.click()\
.move_by_offset(300, 0)\
.click()\
.move_by_offset(0, 400)\
.click()\
.move_by_offset(-50, -50)\
.double_click()\
.perform()
drawing.perform()
time.sleep(2)
The bottom_label used to point the mouse at the end of web page then sleep to start again change offset, click and close the polygon.
This code with Selenium version does not work probably. What should I do to draw the polygon through move and click the mouse?

Consider using a FluentWait, ImplicityWait and setScriptsTimeout Instead of Sleep.
See further documentation
http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebDriver.Timeouts.html

The problem was with the new version of Selenium and Firefox.
I changed to the Chrome driver and the click function works fine.

Related

Getting error Element not interactable on trying to send Page Down keys to div

I am trying to scroll Telegram using selenium in python. In the attached screenshot I have shared I have selected 'Members' as the element to send Keys.PAGE_DOWN as it is stick all the time to top and is static while scrolling so it should be visible all the time and can be the perfect element to send Keys.PAGE_DOWN to.
But on sending page_down I get error 'Element not Interactable'.
Any suggestions what I am doing wrong?
I have attached the script and screenshot.
I am using python 3.10 and selenium latest version.
`driver.find_element(By.XPATH, "//*[#id='RightColumn']/div[2]/div/div/div[2]/div[2]/div[1]").send_keys(Keys.PAGE_DOWN)`
I have tried all the answers currently available on the internet and they don't work here. This looks like some complex issue.
I think Selenium is throwing the right error message as this div is not an interactable element and you are trying to send keystrokes into the element.
Another approach for scrolling is using Javascript commands.
Find an element locator you need to scroll to.
(Ex: if you need to scroll to the bottom find the element at the bottom)
Use the below code to scroll
# Find the element in the page to scroll to
element = driver.find_element_by_xpath("//element/at/bottom/of/the/page")
# Fire javascript command to scroll in to view
driver.execute_script("arguments[0].scrollIntoView();", element)

Trigger to capture screenshot if specific text appear on screen

Is there any solution for this issue that trigger to capture screenshot if specific text appear on screen?
E.g. Need to watch my screen if “NeedToCapture” appear on screen take screenshot, and contine till i stop it.
I try Autoit but it wont have realtime text detection.
Any idea?
Thanks
“NeedToCapture” is on the web page or one desktop applicaiton?
you can refer to the following sample code:
import os
from clicknium import clicknium as cc, locator, ui
elem = cc.wait_appear(locator.app.element, wait_timeout=300)
if elem != None:
file_path = os.path.join(os.getcwd(),"screen.png")
ui(locator.explorer.list_1).save_to_image(file_path)
locator.app.element and locator.explorer.list_1 can be recorded by clicknium recorder, you can find the extension from visual studio code extenion page.
for exampple, the locator of 'locator.explorer.list_1' similiar as the following:
locator of the screen

Selenium , Python and Chrome Webdriver problem

I am learning Python and attempting to build a program that will scrape specific data from a website, store it and then manipulate it.
Currently I run my application, it opens a new chrome browser window and loads the page correctly. The problem is it should begin to start scrolling down and loading the remaining elements on the page.
I know the code works because if I manually click somewhere on the page that doesn't normally illicit a response (white space/empty areas) the browser somehow comes into "focus" and begins to iterate through the loop that scrolls down the page (by sending keys) prints the data I am after. I also noticed if I click another similar "dead space" area that contains the header, it doesn't have the same effect. I am unsure if this is something specific to Chrome, iFrames or something of that nature but I am completely stumped and would greatly appreciate any help.
Any thoughts on why I need to manually click on the new chrome window for it to work would be great.
Update: Still having the same issue, even tried with Safari and the same problem seems to exist.
Fixed this with:
element = driver.find_element_by_css_selector("div[id^='app-container']")
action = ActionChains(driver)
action.click(on_element = element)
action.perform()

How to scroll a webpage using selenium webdriver in Python without using javascript method execute_script()

I am trying to scroll a web page by using mouse and scroll bar. I am exploring any other option than
"driver.execute_script("window.scrollBy(0, 5000'))"
I did try options like chrome actions, however nothing seems to be working.
Would need some guidance if anyone has any idea how to solve this.
If your usecase is to scroll() the window containing the DOM document, there is no better way other then using the either of the following Window Methods:
Window.scrollBy()
Window.scrollTo()
If your usecase is to scroll() an Element there is no better way other then using the Element Method:
Element.scrollIntoView()
You can find a detailed discussion in What is the difference between the different scroll options?
However, if you want to avoid the execute_script() to interact with a WebElement you have two (2) other options available as follows:
Using move_to_element() from selenium.webdriver.common.action_chains. This method will automatically scroll the element within the Viewport.
Example code:
menu = driver.find_element_by_css_selector(".nav")
hidden_submenu = driver.find_element_by_css_selector(".nav #submenu1")
ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform()
Using element_to_be_clickable() from selenium.webdriver.support.expected_conditions. This expected_conditions when used in conjunction with selenium.webdriver.support.wait will automatically scroll the element within the Viewport.
Example code:
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Cart"))).click()

Python 3 - Click a line in a pulldown menu only visible with mouse-over

I am trying to automate the process of logging into a website and downloading reports.
When choosing which report to download you have to mouse over a menubar on the website and hovering the mouse over the right tab will open a pulldown menu where you then click the report you want.
Screenshot of the pulldown menu (sorry, but no points embed the image :( )
I have little experience with coding and I am very new to Python 3 so I am struggling on how to do this.
Using Selenium library I am able to find things such as the user and password fields and pass in the information to automatically log into the site. But not sure how to grab or point at the correct report in this pulldown menu in order to simpy click it.
Here is a snippet of the page source... the class name = rmText... and the class name is same for all of them... only the text inside the <span> is unique but I don't know how to grab that with the Python 3 code.
Screenshot of the page source
I know of a way to do this using VB script... but I would prefer to stay with Python 3 (and also learn how to do this via Python in the process). The example below was used for a similar report where multiple lines had same class-name and we needed just the one called "Infill". An example code of the VB script:
Set project = .Document.getElementsByClassName("UPC_Items")
For Each elm In project
If instr(elm.innerhtml,"Infill") then
elm.Click
Exit For
End If
Next
How can I achieve the same using Python 3? And is Selenium the right library to use?
Thanks for reading and hopefully helping out a newbie in Python!
try below code, hope this helps:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
drive = webdriver.Firefox()
driver.get('your url')
....
steps to reach your place where that menu link is presert
....
element = driver.find_element_by_class("rmText")
putmouse = ActionChains(driver).move_to_element(element)
putmouse.perform()
time.sleep(2)
texttoclick = driver.find_element_by_xpath(".//li[#class='rmText']//span[text()='MCC']")
actions.move_to_element(texttoclick).click().perform()

Resources