error Element //..... not found - xpath

I got an error [error] Element //div[#id='newslist_config']//button[#type='button'] not found when I use auto run to run my selenium test but if I click at the command and choose Execute this command The tests pass. Could you tell me why selenium can not find that element?
My selenium test is
<tr>
<td>click</td>
<td>//div[#id='newslist_config']//button[#type='button']</td>
<td></td>
</tr>
The html is
<div id="newslist_config" class="section-box span8">
<div class="accordion-group">
<div class="accordion-heading">
<h3>News-List Configuration</h3>
<a class="btn btn-danger close_newslist_config" data-dismiss="modal" href="#">remove widget</a>
<button class="btn btn-info collapse-btn" type="button" href="#collapse_newslist" data-parent="#newslist_config" data-toggle="collapse">
<span class="edit-btn-txt">
<span class="collapse-btn-txt">
</button>
</div>
<div id="collapse_newslist" class="collapse collapse-box">
</div>
</div>

You could instead try the xpath: //div[#id='accordion-heading']/button[#type='button']
This is a more direct path; if it does not work I would suggest trying to click one of the containing spans as sometimes, due to styling, clicking an elements span achieves more consistent results. I sometimes have this issue when working with WebDriver in KendoUI.

Approach:
1.Derive the CSS Selector from the given DOM.
css=#newslist_config .collapse-btn
2.Perform the click
driver.findElement(By.cssSelector("#newslist_config .collapse-btn")).click();

Related

Selenium Firefox span tag

I'm having a problem with selecting an element by linkText which is located in a span. In Chrome it works perfectly but in Firefox it doesn't for some reason and i can't understand it for hours already. I'm trying to locate the element as follows: login.wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Kassa"))).click(); However it simply doesn't find it. I noticed that all other elements that are located in the upper navigation bar and the text isn't in a span tag it finds easley, however thous that are in the span it can't find. What is the difference and what is the best way to reach to that element. Because in this case finding by linkText seems to be perfect. Thank you! HTML attached:
<nav class="site-navbar navbar navbar-inverse navbar-fixed-top bg-teal-600" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<div class="navbar-brand site-gridmenu-toggle" data-toggle="gridmenu">
<span class="navbar-brand-text">whatever</span>
</div>
<button type="button" class="navbar-toggle hamburger hamburger-close collapsed" data-target="#site-navbar-collapse" data-toggle="collapse">
<i class="hamburger-bar" aria-hidden="true"></i>
</button>
<button type="button" class="navbar-avatar navbar-toggle padding-horizontal-0" data-toggle="dropdown" href="#" aria-expanded="false" data-animation="scale-up" role="button">
<span class="avatar avatar-online" style="top: -3px">
<img src="https://whatever.png" alt="..."> <i></i>
</span>
</button>
<a type="button" href="https://whatever" class="navbar-toggle padding-top-15 padding-horizontal-0">
<span class="btn btn-warning"> Kassa </span>
</a>
Code snippet:
System.setProperty("webdriver.gecko.driver","C:\\Utility\\BrowserDrivers\\geckodriver.exe");
driver = new FirefoxDriver();
wait = new WebDriverWait(driver, 10);
driver.manage().window().maximize();
Then i'm going to the webpage, through basic authentication , won't post this data here and basically on the page that i land i want to try to find the element like that:
login.wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Kassa"))).click();
Picture of the nav. bar nav. bar
Although if a certain code works on chrome it should work on firefox as well; but if it isn't working then you can try to find the said element using following :
UPDATED:
WebElement navElement = driver.findElement(By.cssSelector("div.container-fluid a>span.btn.btn-warning"));
Actions action = new Actions(driver);
action.moveToElement(navElement).click().build().perform();

Laravel Form Button Cancel

Using Laravel, I have a form and I want to include a "cancel" button that just redirects back to a different route. Since the button is within the form element, when clicked it attempts to submit the form. In the Laravel docs I don't see a good way to do this. Any suggestions or would using Javascript be best?
Thanks,
<div class="form-group pull-right">
<button class="btn btn-default btn-close">Cancel</button>
<button type="submit" class="btn btn-global">Register</button>
</div>
Though it's a very late answer, But it might help others.
You can just redirect back where you have come from. Simply use the following code.
Cancel
It will send you back where you have came.
<a> elements in bootstrap can have the btn class and they will look just like a button, so you can take the button out and just have cancel be a link:
<div class="form-group pull-right">
<a class="btn btn-default btn-close" href="{{ route('home') }}">Cancel</a>
<button type="submit" class="btn btn-global">Register</button>
</div>
it does not have to do with laravel. You can simple use formaction attribute
<input type=submit formaction="anotherpage">
<button class="btn btn-default btn-close" formaction="{{ route('home') }}">Cancel</button>

font-awesome to be inserted in value="<spring:message text="View List"/>">

im trying to insert some font-awesome inside here
<form action="/someweb.html">
<input type="submit" class="btn btn-success" value="<spring:message text="View List"/>">
</form>
but it seems that this code
<i class="fa fa-list-ul fa-lg"></i>
wont fit inside, and i tried to insert it inside in different position, i always get failed result. all i wanted is to have this kind of look here.
hope you could help. thanks in advance.
I have not tried it completely, but this should give you an idea.
<form action="/someweb.html">
<button type="submit" class="btn btn-success"><i class='fa fa-list-ul fa-lg'></i><spring:message text="View List"/></button>
</form>
Here is a sample in codepen.
http://codepen.io/anon/pen/yNXvZw

xpath preceding-sibling not working

I am trying to click on the first button which deletes the item which is the second button.
<tr>
<td>
<div class="btn-group">
<button class="btn btn btn-danger" name="delete" type="button">
</div>
</td>
<td>
<span class="class"></span>
</td>
<td>
<button class="btn" name="item" type="button">
</td>
</tr>
XPath
//button[contains(.,'${ITEM}')]/preceding-sibling::button[#name='delete']
I'm going to assume you're just not showing us the button text in your example HTML, since neither of your buttons seems to have any content.
preceding-sibling would not work here, since the two buttons are not siblings. However preceding::button should work in this case. Note the [1] at the end which is needed in order to select the closest match:
//button[contains(.,'${ITEM}')]/preceding::button[#name='delete'][1]
The following should also work, and is in my opinion a bit cleaner:
//tr[.//button[contains(., '${ITEM}')]]//button[#name ='delete']

Why does a Bootstrap modal not fire in a button, but only with Firefox?

I'm putting up a Bootstrap "split button" modal, which looks something like this:
<div class="btn-group">
<button class="btn btn-small btn-primary">
<a tabindex="-1" href="#" class="ajax-modal"
data-target="modal_vr-comment-form" data-backdrop="true"
data-controls-modal="res-modal" data-keyboard="true"
url="/some-url">Do the thing</a>
</button>
<button class="btn btn-small dropdown-toggle btn-primary" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu pull-right">
<li><a tabindex="-1" href="#" class="ajax-modal"
data-target="modal_vr-comment-form" data-backdrop="true"
data-controls-modal="res-modal" data-keyboard="true"
url="/some-url">Do the thing</a></li>
<li><a tabindex="-1" href="/comment/something-else">Do something else</a></li>
<li><a tabindex="-1" href="#" class="ajax-modal"
data-target="modal_unhide-people" data-backdrop="true"
data-controls-modal="res-modal" data-keyboard="true"
url="/comment/do-another-thing">Do another thing...</a></li>
</ul>
</div>
The thing of interest here is that the "Do the thing" action is presented in two ways: As an action to be taken when the main button is clicked, and as an action to be taken when an item in the dropdown menu is selected. These actions are set up as click handlers on the <a> tags in the split button, via some javascript init-ing.
Both actions work fine in Chrome and Safari. However, in Firefox, the action attached to the button does NOT fire, while the action attached to the link does. Some poking around during execution reveals that the click handler on the button is not firing, although it's definitely getting set up.
Any ideas out there about why this is (happening)? Thanks!
Found it, more or less: Twitter Bootstrap buttons are unresponsive in IE8 had a working approach. Instead of formatting the button as:
<button class="btn btn-small btn-primary">
<a tabindex="-1" href="#" class="ajax-modal"
data-target="modal_vr-comment-form" data-backdrop="true"
data-controls-modal="res-modal" data-keyboard="true"
url="/some-url">Do the thing</a>
</button>
do it as a pure <A> link with the appropriate button-style classes:
<a tabindex="-1" href="#" class=" btn btn-small btn-primary ajax-modal"
data-target="modal_vr-comment-form" data-backdrop="true"
data-controls-modal="res-modal" data-keyboard="true"
url="/some-url">Do the thing</a>
The appearance is identical, and it works fine in Firefox, IE, and Opera (both platforms). Whew.
I just had the same problem in 2019 (Bootstrap 4.3.1, Firefox Quantum 69.0) and found this post from 2011 that solved the problem for me: just remove the animation for the modal (remove the "fade" class from the parent div). Original post is here: http://chapter31.com/2011/10/27/twitter-bootstrap-modal-not-working-in-firefox/

Resources