Unable to select drop down button for python selenium - selenium

How would I select this button
and click on it?
I have tried several methods and none of them have clicked it.

try with css selector and javaScript executor for select multi-class element and click it
driver.execute_script("document.querySelector('button.btn-select.nowrap-line')[0].click()")

Have you tried the class_name selector?
element = driver.find_element_by_class_name("btn-select nowrap-line")
I know you said you've tried several methods, maybe list the different ways and I can probably try to see why it's failing

Related

Unable to click on Radio Button

Please, I don't know why but I can't click on this radio button.
I'm trying by xpath, css, id... but anything works.
Always I get the error: no such element: Unable to locate element
And I added an explicit wait, but it still not working.
Now, I'm trying it but not works as well:
WebElement radio = driver.findElement(By.xpath("//div[#class='form-inputs-container']/ul/li[3]/label"));
radio.click();
I need click on multiple destinations radio on this website:
https://www.turismocity.com.br/
Can you help me, please ?
RadioButton
It looks like your xpath is wrong Try with below xpath it will work
//form[#class="tc-form-full-flight"]//label[#for="tt1"]/following-sibling::div
For first radio button: //form[#class="tc-form-full-flight"]//label[#for="tt1"]/following-sibling::div
For second radio button: //form[#class="tc-form-full-flight"]//label[#for="tt2"]/following-sibling::div
For third radio button: //form[#class="tc-form-full-flight"]//label[#for="tt3"]/following-sibling::div
Hope this will be helpful!!!
This should work //input[#id='tt3'] or //input[#value='MultiDestino']
You can evaluate xpath in chrome console like this $x("//input[#value='MultiDestino']")
The xpath you have returned empty []
Locator is incorrect. More than that - even if it was valid, this way of finding elements is unreliable (you've used an element position - [3] in case of order change, locator will brake). I suggest css selector:
input[value='MultiDestino']
For locators, you should always start with something that is highly unlikely to change. Typically that's IDs, names, and various other custom attributes depending on the site. In this site's case, the three radio buttons you are looking at each have an ID.
Side note... sometimes sites/pages don't respect HTML standards that require the ID to be unique on the page so even if your desired element has an ID, always check to make sure it's unique on the page. In this case, the IDs are unique.
To click the multiple destinations radio button, you can use the code below.
driver.findElement(By.id("tt3")).click();
In some of your comments, it looks like Selenium might be having a hard time clicking on the INPUT itself and the LABEL is working. If that's the case, then you can change the locator slightly and use the code below
driver.findElement(By.cssSelector("#tt3 + label")).click();
In the CSS selector above, # means ID and + means next sibling. See the W3C docs for more info.

Selenium Webdriver selecting wrong input in jquery dialog

I am testing a site that has a dialog box with multiple text fields, some with datepickers, some without.
For some reason, when I attempt to locate the inputs by their XPath selenium finds the element, but when it comes time to input data, it send the keys to the top field. Here is an example of my selenium code:
DriverHelper.SendKeysByXpath("//input[#name='registrationStartDate']",CurrentDate);
DriverHelper.SendKeysByXpath("//input[#name='firstStartDate']",CurrentDate);
DriverHelper.SendKeysByXpath("//input[contains(#name,'lastStartDate')]","01/01/2018");
FYI, the DriverHelper is a class I call to save myself from typing the same selenium calls over and over again.
The XPath names are all unique and as far as I know there shouldn't be any confusion as to which input I'd like to send the keys to.
Has anyone run into similar situations before?
I'm trying to get an example up in jsfiddle but so far I'm unable to replicate the issue there.
It is sending keys to the top element probably because that is the one that he is selecting.
Try to use this:
List<WebElement> result = webDriver.findElements( by );
Debug your code and check how many elements your selector is retrieving.
Try to narrow and improve your search in such a way that you narrow the group os selected elements as possible.
Very personal opinion:
The code is easier to fix and to read if you avoid using xPaths as selectors. I prefer id's and classes whenever its possible.
Selenium best pratices source

Click Button With No ID Selenium Java

Apologies for this;
Event Triggers
Photos
Push Notifications
How can I Click on Event triggers for example using Selenium Java?
I've tried this code:
By.xpath("//button[contains(text(),'Event triggers')]");
By.xpath("//button[contains(text(),'Submit')]");
I tried this as well:
WebElement Box= driver.findElement(By.tagName("Event triggers"));
Box.submit();
Neither of these worked...
Thank you
Try to using this:
By.xpath("//a[contains(text(),'Event triggers')]");
instead of
By.xpath("//button[contains(text(),'Event triggers')]");
Based on the page source mentioned in the comment I think Event Triggers is not a button but an tag which essentially makes it a link.
As you know the text of the link you are trying to click you can always use:
driver.findElement(By.linkText("Event Triggers"));
to get Event Triggers web element.
Using xpath should be avoided due to slow performance.
Well, if button doesnt have any id , you can try to write dynamic xpath by using "class name" and "type" (there are plenty of examples , you can learn easily how to create your xpath) , or easiest way, use firebug to locate element that you want to click and copy exact Xpath via firebug. And then click.
The correct answer is:
By.xpath("//button[contains(text(),'Event triggers')]").click();
You were missing that click action.

Selecting element with multiple classes in Capybara

I'm writing automation code in Capybara with Selenium.
I have the following element in my HTML, and I wanna click this element in Capybara.
click me
At the moment, the way worked is something like following.
find('.classA', :text=>"click me").click
But I wanna select the element from the names of the two classes like this
find('a.classA.classB').click
click_on('a.classA.classB')
I know we can get javascript code fired, but this is not smart.
page.execute_script('$("a.classA.classB").click()')
You can search an element by xpath
based on your example, seems like the following should work
//div[contains(#class, 'classA') and contains(#class, 'classB')]
You could also use css
(:css, ".classA.classB")

SVG and selenium

Hej Guys
I an using google visualization api to draw stacked bar chart. Its all fine but now i want to test it with selenium but having a hard time finding the elements in the google chart.
For example i want to click on the chart element but everytime i try to find an element by xpath i get exception "OpenQA.Selenium.NoSuchElementException: The element could not be found"
I read that with selenium its tricky to click on the svg images.
Is there anybody who know a solution cuz i m kind of desprate and i havent find a suitable solution on the net by myself.
My chart looks like this:
http://i48.tinypic.com/21o4swx.png
What i am trying todo is:
webdriver.Navigate().GoToUrl("http://localhost:59777/Tests/TestsMainView");
IWebElement element = webdriver.FindElement(By.XPath("/html/body/div/div[2]/div[2]/iframe/html/body/div/svg/g[2]/g/g[2]/rect[5]"));
Actions myAction = new Actions(webdriver);
myAction.Click(element).Perform();
Thread.Sleep(9999);
Thanks :)
Here is some advice that may help you. First your second line of code is should be
WebElement element = webdriver.FindElement(By.xpath("//img[contains(#src,'http://i48.tinypic.com/21o4swx.png')]"))
You had "IWebElement" (this was probably just a typo in your question). I changed the way the element is found searching for matching element instead of starting at the top level and working down. This is a better practice to narrow down the element you are attempting to interact with so that changes to the code don't instantly break your test. Also unless you start an xpath expression off with "//" or "xpath=" selenium Webdriver will not recognize it so even if your path never changed selenium Webdriver wouldn't be able to find it.
If I understand what you are trying to do then you can also remove lines 3-5 and replace them with the following,
element.click();
This will have selenium Webdriver zoom in on the chart provided by your link. I hope this helps
I noticed xpath cannot select anything within an svg tag. I managed to find elements using className or tagName selectors instead or you could even try cssSelectors but I am not sure about that one. Note that you can still use xpath to access parents of a node inside an svg using:
By.xpath("..");
Hope that will help.