How to select an option from a drop down? - webdriver

When I'm trying to select any one of the options from a drop down "Birthday" on Google account creation page using .xpath, I found the xpath as follows:
.//*[#id=':a'] but it was not selecting the desired option the drop down. But, when I added /div at the end of the same xpath i.e .//*[#id=':a']/div it worked.
Can anyone explain why I should add /div at the end?

It was happened because your proper Element is //*[#id=':a']/div not just //*[#id=':a']
See the image below :-

Related

ng-bootstrap / in case of multiple ngbNav in same page, contents are never displayed but those of first instantiaed ngbNav

[ng-bootstrap] in case of multiple ngbNav on same page, contents of second and below navs are never displayed with ngbNavOutlet directives, but the first only (looks like it can recall ng-template of first ngbNav only).
thx for your help.
I see there is the same id used for the first and the second nav panels. Just make it unique and both nav panel will work well.
Use the attribute from the API domId
[domId]="unique-id-here"
https://ng-bootstrap.github.io/#/components/nav/api

Robotframework . How I handle collapsible menu?

I try to use Click Element id=elementid in Robotframework.I have Selenium2 Library.I have a Menu collapsible.See little arrow on Entity 1 on first print screen.I try to identify the element id.I cannot see element id when I inspect this.I see only jotid that I do not think is the same.So, I am not able to use click element in order to expand my menu.I appreciate anyone's help as I am still learner.Please see also the images of a) Code, Menu, Inspected Element
You can also find it using xpath, so:
Click Element | //li[#wuid="gx:309..."]
jotid is not id, so you cannot locate it by id.
You could try keyword:
Click Link ENTITY 1 -Introduction
or find it by css:
Click element css=a[jotid='wuid:gx:4286...<the rest of it>']

Nightwatch Cannot Find/Click on Dropdown Option

I'm a backpacker and a programmer, trying to use the second skill to find openings in a full campsite. Rather than crawling fro scratch, I'm using the end-to-end testing framework nightwatch.js to navigate for me.
I've hit a roadblock, because nightwatch is having difficulty finding a specific element using css selectors.
Here are the elements and page:
Here is my test code:
Previous Attempts
My test code will click on the selection box with #permitTypeId. It will see that #permitTypeId option is visible. It will not see or click on any of the options when more specific values are specified. The five .click()'s are all css selectors I've already tried. None of the options are set to display:hidden or display:none. I have also tried all of the above without the .waitForElementToBeVisible() just in-case the waiting causes the dropdown to hide.
I've successfully clicked options from different dropdown menus on this website without any problem. Just this one is causing a headache.
The tests are running with the most current Selenium server and Firefox on Mac Yosemite.
tl;dr
Nightwatch.js/Selenium won't click on something from a dropdown menu.
The Path...
Cory got me thinking about jQuery and native DOM manipulation. Tried going that route and was successful selecting the correct option using Selenium's .execute() function:
.execute('document.getElementById("permitTypeId").options[1].selected=true')
However, it was not triggering the onchange event.
Saw this post which made me start thinking about using key-strokes and this one which suggested using arrow-keys to navigate down a <select> element to the option, then hitting enter.
...to the Solution
.click('select[id=permitTypeId]')
.keys(['\uE015', '\uE006'])
I've found that this is an issue with Firefox. Chrome and PhantomJS operate well clicking <option> tags.
you should be able to click like this way
browser.click('select[id="permitTypeId"] option[value="1451140610"]')
Additionally I was able to add a .click event for the specific option once I did a .click for the select. see my example below:
.click('select[name="timezone"]')
.pause(1000)
.click('option[value="America/Chicago"]') //selects the option but doesn't click
.pause(5000)
.keys(['\uE006']) //hits the enter key.
another solution:
.click('select[id="permitTypeId"]')
.waitForElementVisible("option[value='1451140610']")
.click("option[value='1451140610']")
Very simple way is to use .setValue('#element', 'value of option')

Not able to click a button which sites inside form which sits under Iframe which sits under table

I want to click a button*-Create Order* which sits under Iframe. In order to do that I need to switch my driver to iframe , for which I need to find iframe first. Now I have tried everything to locate this iframe.When I started digging in I relaized that if I do this
WebElement table= dr.findElement(By.xpath(or.getProperty("html/body/div[4]/form/table/tbody/tr[2]")));
I get some value for the table.size()
But if I do this :
WebElement table= dr.findElement(By.xpath(or.getProperty("html/body/div[4]/form/table/tbody/tr[3]")));
I get 0 count.
I have spent so many hours to get to this frame.When I failed with cssSelector or xpath I started going by each node and that's how I found this.
Please help.
Assuming you are using Java, you can address an iframe with SwitchTo().Frame() in three ways
By iframe name or id. If the iframe has name="frameName" or id="frameID", you can use dr.SwitchTo().Frame("frameName") or dr.SwitchTo().Frame("frameID").
By iframe element. You can address an iframe by something along these lines:
dr.SwitchTo().Frame(dr.findElement(By.Css("table>tbody>tr:nth-child(3)>iframe")));
By count, starting from 0. You can address an iframe by:
dr.SwitchTo().Frame(0), which would switch to the first iframe.
For #2, we can give you better help on a CSS selector if you include some html including the iframe in question, and a few lines above it in your question.

capybara - Clicking a button without an id

I'm trying to to click the button in this html code
<div class="modal-footer"><button class="btn" data-dismiss="modal">Kapat</button></div>
I've already tried find with various combinations, the closest I came to success was with this code:
click_on "Kapat"
The problem is that there are 3 copies of the same button in the page, so my question is; is there a way to specify this particular div ?
If the button has a specific path, you could use within or a find down to that path, but that path to the element would have to be unique in the page or you end up with the same problem (though, I believe using :xpath would give you a bit more flexibility here).
within ".modal-footer" do
click_on "Kapat"
end
within ".another-selector" do
click_on "Kapat"
end

Resources