How to select context menu items without keyboard input in selenium webdriver? - selenium

I am able to select the context menu item by providing keyboard input. i just wanted to know whether there is any way to select a context menu item without keyboard input in Selenium WebDriver.
Thank you for your help.

Once you have the ContextMenu displayed via Selenium, you can then use SendKeys to send down key presses until the correct option is selected followed by an enter key. If this isn't working as separate calls try and perform the ContextMenu and all the key presses sequentially using the Action class (eg. build the action sequence and then perform() them).
A list of Java Selenium Key Enums can be found here.

Related

How to keep the dropdown list open in robot framework

Here, I will click the actions tab and select create new project from the drop down list.
While executing the script in robot framework, after clicking the actions tab the drop down list will be opened and after few seconds it automatically got closed.
I need to know how to keep the list to be in open.
Most likely, what is happening is that the library you use to create the dropdown is designed to dismiss the dropdown when the mouse leaves the dropdown. If that is the case, the solution is to first move the mouse over the dropdown before clicking on it.
The SeleniumLibrary has a Mouse over keyword that will simulate the mouse being over the element.

selenium, hidden button by overlapped input ( not clickable)

Is there any way on how to click a hidden button by an overlapped input text field, for example if you go to www.google.com and enter a text to search for, selenium can not find the "Search Google" button because it is hidden by the autocomplete of the text field.
Thanks.
You can bypass the validation by using #click! instead of #click. Basically, this triggers the click via JavaScript rather than through standard Selenium commands.
browser = Watir::Browser.new
browser.goto('www.google.com')
browser.text_field(name: 'q').set('watir')
browser.button(name: 'btnK').click!
If you are only using Selenium, you can do:
btn = driver.find_element(name: 'btnK')
driver.execute_script('arguments[0].click();', btn)
As discussed in the comments, you could also close the suggestions box before trying to click the button. You can do this by moving focus to any other element - eg the first link on the page. Depending on what you're testing, this may or may not have value.
browser.text_field(name: 'q').set('watir')
browser.link.focus # move focus to any other element so suggestions close
browser.button(name: 'btnK').click

How can I select always the last radio button?

I have a verification page to test by selenium webdriver automation. On the verification page there are always three questions.
But those questions are selected from a pool of questions and so for a single user different questions might appear every separate time he comes to verification page.
So say there are 20 questions in my pool and there are five options (radio answers) for each question, so there are 100 separate radio buttons and each has its separate id/name in DOM.
I am unable to automate this piece of the webpage.
In order to proceed with my testing, I need to always select the last radio button for each of the three questions.
The last radio always contains either "None" or "never" in the label text and radio text label is clickable.
Also the name locator always starts with "1402248" for each radio button.
I am using Page object model in my projet.
Can someone help me to understand how can I identify each radio webelement?
I am using this:
#FindBy (xpath = "//*[#class='radio']//a[contains(text(),'never') or contains(text(),'None')]")
protected WebElement oVerifyIdentityFirstAnswer;
This CSS selector should find all radio buttons that are last of their type inside a parent element
driver.findElements(By.cssSelector("input[type='radio']:last-of-type"))
If your radio buttons are all encapsuled individually, move the last-of-type to that container element:
driver.findElements(By.cssSelector("a:last-of-type" > input[type='radio']))
This returns a list of WebElement, which you can iterate over and click every entry. I wouldn't use the #FindBy annotation by the way, since it often leads to staleness exceptions.
Try changing your Xpath to:
xpath = "//*[#class='radio']//a[contains(text(),'never') or contains(text(),'None')][last()]"

How to assert a button's property

I am using selenium web driver and currently automating a registration form. There are various fields like username,password etc which we have to fill in the details and click on the terms and conditions check box and the account create button gets enabled.
Right now there is some issue with the java script and all my assertions for the create account button is failing. Is there any way I can work on this issue?
possible solution:
apply getAttribute() function to the element you need. And compare data obtained with expected data to be:
WebElement button = driver.findElement(By.xpath(..blablblalb...));
String color= button.getAttribute("color");
//verifyinh that color is that of expected
Assert.assertTrue(color.contains("red"));

Cannot click Submit button on Selenium IDE

I am having trouble getting Selenium IDE to click the Submit button on one of my webforms after having selenium open and fill out the form. I am using the clickAndWait command and identifying the button by its ID:
<td>clickAndWait</td>
<td>id=ctl00_ContentPlaceHolder1_OSVFHResults_btSave</td>
<td></td>
Interestingly, if I write a script that simply opens the form and clicks the submit button without filling it out, I am not having any problems. My problem is coming specifically after I've asked Selenium to fill out the form. Additionally, if I try to manually click the submit button, it doesn't work if the Selenium script to fill out the form was run before my manual input. If I manually open and fill out the form, I have no problems clicking submit, and Selenium works for all of the other form's submit buttons on the site. Anyone have any ideas?
Instead of filling form with type command you can try typeKeys one. It simulates keystroke events on the specified element, as though you typed the value key-by-key and probably enable your submit button.
It sounds like some javascript event unrelated to click() (such as mouseover or onkeydown) is attached to one or more of the form fields and is responsible for enabling the submit button.
You'd have to look at which exact events are being fired, either by looking at the source with something like firebug, or by using a javascript debugger. Then modify your Selenium script to make sure the same events get triggered.
After type the values in the form just try "ClickAtandWait" instead of "clickandWait"..i also face the problem once and it gave hands once..
selenium.clickAtandWait("locator", "position");
if you know the exact "position" just put it, otherwise leave it as an empty string.