I am inputting an address in a text box which dynamically displays an address (powered by google). I need to click the down arrow and hit tab to select an address. I tried Press Key but it did not work. So, I tried the below extended library. So, when in my test case, i call this in settings, Library ExtendedSelenium.py and in the Test case section, I called press_down_arrow. Still it does not press the down arrow. Am I doing wrong? Do I need to supply any ID or values? Kindly help
# ExtendedSelenium.py
from SeleniumLibrary import SeleniumLibrary
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
class ExtendedSelenium(SeleniumLibrary):
def __init__(self):
super(ExtendedSelenium, self).__init__()
def press_down_arrow(self):
""" Emulates action "press down arrow on keyboard".
"""
ActionChains(self._current_browser()).send_keys(Keys.ARROW_DOWN, Keys.NULL).perform()
Related
This question already has answers here:
How to handle HTML constraint validation pop-up using Selenium?
(3 answers)
Closed 3 months ago.
I am trying to get the text of the mouseover on the login page from the email field.
This is the site "https://app.involve.me/login/?_ga=2.49216998.1374332121.1660294616-36640509.1660294616"
If you will leave the fields empty and try to log in a popup will appear with the following message:
Please fill out this field
I cannot get the text from it. I tried as an alert, tooltip nothing works. There is no path to it.
Element snapshot:
The text of the mousehover on the login page from the email field which you are referring is the outcome of Constraint API's element.setCustomValidity() method.
Note: HTML5 Constraint validation doesn't remove the need for validation on the server side. Even though far fewer invalid form requests are to be expected, invalid ones can still be sent by non-compliant browsers (for instance, browsers without HTML5 and without JavaScript) or by bad guys trying to trick your web application. Therefore, like with HTML4, you need to also validate input constraints on the server side, in a way that is consistent with what is done on the client side.
Solution
To retrieve the text which results out from the element.setCustomValidity() method, you can use either of the following Locator Strategies:
Using Python and CssSelector:
Code Block:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
driver.execute("get", {'url': 'https://app.involve.me/login/?_ga=2.49216998.1374332121.1660294616-36640509.1660294616'})
print(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='email']"))).get_attribute("validationMessage"))
Console Output:
Please fill out this field.
Using Java and Xpath:
Code Block:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class validationmessage {
public static void main(String[] args) {
driver.get("https://app.involve.me/login/?_ga=2.49216998.1374332121.1660294616-36640509.1660294616");
System.out.println(new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[#name='email']"))).getAttribute("validationMessage"));
}
}
Console Output:
Please fill out this field.
Im making robotframework automation tests cases
I need to click on button which is in the same line another element. I need to verify the color of the element and click on button. I need to verify it cuz the validation after clicking on button depends on the type of the option I clicked. There are two options, the option which blue and red color.
enter image description here
I would do a custom keyword(s) in Python, that will
${list_of_rows_buttons_to_click}= Get Buttons To Click
get table data AND styles
possibly de-serialize previous
go trough rows
if style "red color" detected in column 2 add row id to return list of row_id:s
Press buttons in Rows ${list_of_rows_buttons_to_click}
Python libraries you most likely need (did de-serializing in numpy myself):
import numpy as np
import requests
from bs4 import BeautifulSoup
from lxml import etree, html
from robot.api import logger
from robot.api.deco import keyword
from robot.libraries.BuiltIn import BuiltIn
lmxl, requests and BeautifulSoup are needed, if you an not get table data easily to Robot Framework - or if you want a bit more graceful solution.
I need to reach a target frame with Xpath = html/frameset/frameset[1]/frame[2].
The HTML tree of the web site is as follows (the target frame is marked with a red *):
The web page is a chat room and I want to get the input box and the send button.
The following code logs into the chat room and tries to get to the target frame, but it fails there (Selenium hangs while trying to switch to that frame):
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome('/home/yky/Downloads/chromedriver')
driver.get('http://ip131.ek21.com/oaca_1/?ot=1')
### Log into chat room:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[#id="mlogin"]/form/ul/li[1]/input'))).send_keys("UserOne")
driver.find_element_by_xpath('//*[#id="mlogin"]/form/div/span').click()
time.sleep(6)
### NONE of these works:
#driver.switch_to.frame(driver.find_element_by_css_selector("frame[name='ta']"))
#driver.switch_to.frame("ta")
#driver.switch_to_frame(driver.find_element_by_xpath('html/frameset/frameset[1]/frame[2]'))
#driver.switch_to.frame(2);
inputbox = driver.find_element_by_name("says_temp")
sendbutton = driver.findElement(By.xpath("//input[#value='送出']"));
I find the suggestion to ignore framesets to be very beguiling, as it doesn't make sense when the framesets contain other frames as a tree structure. Also, the problem is that the first frameset does not contain any frame; it just contains another frameset. So there is no way for Selenium to switch to the first frameset.
Please help!!
I am writing selenium (python) tests for a site that contains a cytoscape.js tree. I am trying to record a ritgh click action on one of the cytoscape's elements (node) but i cannot find a way to do it in python and when i create the test in browser using the selenium IDE is nt recording actions on cytoscape.
To perform a right click in Python, you'll need to use the context_click action from ActionChains.
from selenium.webdriver import ActionChains
driver = webdriver.Chrome()
actionChains = ActionChains(driver)
web_element_to_click = driver.find_element_by_id("someId")
actionChains.context_click(web_element_to_click).perform()
If you cannot locate a web element to click (due to dynamic browser page), you may need to click by coordinates instead, by moving the mouse to the coordinates then performing context_click:
# move_by_offset moves your mouse from its last known location to given x,y offset
ActionChains(driver).move_by_offset(x,y).context_click().perform()
I am writing UI tests for my QT app with selenium + qtwebdriver, and I have one moment in app, which I need to test: user can perform right mouse button click -> some menu showed up and user can click in this menu. I tried this code:
#!/usr/bin/env python
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains
import time
driver = webdriver.Remote(command_executor='http://127.0.0.1:9517',
desired_capabilities={"browserStartWindow": "*", "reuseUI": True})
driver.get("qtwidget://MainWindow")
action = webdriver.ActionChains(driver)
action.move_by_offset(7, 87).context_click().move_by_offset(10, 91).click().perform()
Context menu appears (so it means, that right button click was performed well, but left mouse click was not performed. How to fix this ? Or maybe I can use other solution ?
Try using 'ARROW_DOWN' to select the option after clicking context click.
action.move_by_offset(7,87).context_click().contextClick().sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.RETURN).build().perform();