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.
Related
I am trying to locate a tweet like button using xPath.
If I go to https://twitter.com/BillGates and use Chrome developer tools, I can see:
That the like button for the first tweet is located at:
/html/body/div[2]/div/div/div[2]/main/div/div/div/div[1]/div/div[2]/div/div/div[2]/section/div/div/div[1]/div/div/div/div/article/div/div[2]/div[2]/div[2]/div[3]/div[3]/div/div/div[1]/svg/g/path
That the first tweet like button has:
< path d="M12 [lots of numbers]">
I tried to use both Python + Selenium and XPath Helper Chrome extension but with both approaches I cannot find the button.
I have tried without success using the full xPath and also the query below:
.find_element_by_xpath("//path[starts-with(#d, 'M')]").click()
Actually, I cannot get anything past the last div. //svg, //g and //path all get zero results. //div on the other hand, gets me 900+ results...
Appreciate if anyone can help to point me in the right direction.
Thanks!
I highly recommend not using Twitter to practice automation.
Anyways, i've seen that the likes buttons has data-testid attribute which it's value is unique to that element you are looking for, so we can easily get all the likes buttons elements like this:
//div[#data-testid="like"]
Or with css selector like this:
div[data-testid="like"]
Assuming you are writing in Python, Then we can use find_elements method to get all the elements in a list.
like_buttons = driver.find_elements_by_xpath("//div[#data-testid="like"]")
And easily click any tweet's like button you'd by index,
like_buttons[0].click() # 0 Is the first tweet, 1 is the 2nd etc...
Note that you might need to perform a hover on this element and then click it,
So if the driver find the element, but it's not clickable, it must be it.
I am searching it from 2 days but still unable to get satisfying answer..please help
I am using liferay, i want to open dropdown which name is "Add" and then want to click on submit button named as "Blank Site"..and both "Add" and "Blank site" button contains dynamic values/id which changes each time..attaching image for reference..
Image: Add
Image: blanksite
Selenium supports wide range of different selectors besides byId. XPath is able to refer to text value inside the tag.
Also using almost any selector you can retrieve list that can be additionally filtered by any rules.
Use Xpath Contains Method:
Based on your 2 attached image, I think the button's text you are looking for is unique in the entire web page.
What you can do to fix the problem:
For the second circumstance(Blank Site):
Xpath: //li/a/span[contains(text(), "Blank Site")]
Suggestions:
Xpath Contains|Start-with Usage
You can use xpath with any combination, one is already suggested by #PedroMiguel other one is like that
//*[contains(#id, 'yui-patched') and contains(#role,'menuitem')]
I am trying to explore log In button xpath with this site https://www.componence.com/login, by just recording and play back.Then I tried to get it through firepath and chrome browser default xpath copier.
But it looks like every time submit button xpath get changed with page load. I got following xpath for "Sign IN" button.
.//*[#id='yui_patched_v3_11_0_1_1487250469606_202']
.//*[#id='yui_patched_v3_11_0_1_1487251369606_202']
.//*[#id='yui_patched_v3_11_0_1_1487250229606_202']
.//*[#id='yui_patched_v3_11_0_1_1487254369606_202']
Can you please help me to retrieve correct xpath of Sign IN button which I can use with selenium IDE?
You can use below XPath to handle dynamic id:
//button[starts-with(#id, "yui_patched_v3_11_0_1_")]
But better solution is to use text content of element:
//button[normalize-space(text())="Sign In"]
I will have to disagree with the second statement of #Andersson, since it will work for .com but not for .nl.
As I see the site has a second language and my opinion is to avoid using selectors based on text on a multi-language environment.
Also as I see the id seems does not have a meaningful value, in this case try to identify a unique parent section and go from there.
One option for css/xpath would be:
css: form.sign-in-form button
xpath: //form[contains(#class, 'sign-in-form')]//button
I am using Selenium in some automation testing. On a certain page i need to click a button. This same page is used multiple times and when i originally tried to use the full xpath it would work on one of the pages but not the other. The full xpath for each page is slightly different so i dont want to use that.
The xpath of the button looks like this
.//*[#id='approve-gen8149262f2cdc49958632185c33b8e82f']
On both pages the id always starts with approve and then gets some generated numbers.
I am wondering if there is a way to search for just a section of the id so i can look for "approve" in order to find the button i need to click.
I have tried a number of things with no luck thus far.
You can also use CSS selector:
[id^="approve"]
Using XPath, you can select an element where one of its attribute begins with a given string. For instance:
//*[starts-with(#id, "approve-gen")]
See also:
Selecting elements whose attribute begins with something in XPath
You can also use the xpath with contains. for eg.
//*[contains(#id, 'approve-gen')]
Make sure that there are no other locators with id starts with 'approve-gen'.
Use
Step 1:
From the Given Info I have assumed the CSS Selector as
css=button[id*='approve-gen']
Also look for the Other Attributes of button that will bring uniqueness.
Step 2:
Perform Click on the button
driver.findElement(By.cssSelector("button[id*='approve-gen']")).click();
Web page contain a button with some text for example "Test". This button actually is a toolbar element. ( class ="tbButton" id="id",text="Test") and redirects to a certain table when press on it.
When try to use the following click methods
selenium.click("id");
selenium.doubleClick("id");
selenium.click("//*[text()='Test'and contains(#class, 'tbButton')] ");
the button does not react
Could enybody show an alternative methods that is able to resolve a problem
It's hard to know exactly what the problem is without knowing more about the actual contents of the page you are testing. Is there an example of the toolbar online somewhere?
With modern interfaces, locating elements with Selenium is not always an exact science. Here are a few suggestions:
With modern interfaces you often find that the DOM is being manipulated, so it is possible that the identifier you are using is no longer valid by the time you get to your click(). Use Firebug to check that you have the correct element.
Often it helps to click on the parent of the element, such as a div or the parent table cell. Again, use FireBug, to try some other elements near your toolbar button. Alternatively, Firebug sometimes reveals that the element contains other elements. You might have more luck changing the target to a contained element instead.
Sometimes you have to play around with some of the alternative actions. For instance, some controls respond to a mouseDown() followed by a mouseUp(), but not to a click(). Again you can often get hints from looking at the source with Firebug.