How to write xpath for li content for breadcrumb items - selenium

I want to write an xpath for verify the Custom Report text without index.
HTML:
<ol>
<li>
Lw2_0702230135
</li>
<li>
Report
</li>
<li>
Custom Report
</li>
</ol>

You can use the following xpath:
//ol/li[contains(text(), "Custom Report")]

Given the HTML:
<ol>
<li>
Lw2_0702230135
</li>
<li>
Report
</li>
<li>
Custom Report
</li>
</ol>
To identify the element with text Custom Report you can use the following xpath based locator strategy:
//ol/li[last()]
Code (Python):
element = driver.find_element(By.XPATH, "//ol/li[last()]")

Related

How to render <ol> with proper indentation and label using react-native-render-html?

I'm using the renderers to alter the indention of the levels however I needed to provide a custom function to identify the proper label.
Here's the payload returned from the API >>>>
<p>sample product</p>
<p><br></p>
<ol>
<li>sample</li>
<li class="ql-indent-1" id="a">sample</li>
<li class="ql-indent-1" id="a">sample</li>
<li class="ql-indent-2" id="i">sample</li>
<li class="ql-indent-2" id="i">sample</li>
<li class="ql-indent-2" id="i">sample</li>
<li class="ql-indent-1" id="a">sample</li>
<li class="ql-indent-1" id="a">sample </li>
<li class="ql-indent-2" id="i">sample</li>
<li class="ql-indent-3" id="1">sample</li>
<li class="ql-indent-4" id="a">sample</li>
</ol>

Bigcommerce How can I set login and register links on header with fortune theme

I'm using Fortune and the 'Login and Register' are at the bottom of the page. Does anyone know how to put it at the top of the page with the other headings.
Please use below code:
{{#if customer}}
<li class="header-navigation-item navigation-item-primary">
<a class="navigation-link-primary" href="{{urls.account.index}}">{{lang 'account_general.your_account'}}</a>
</li>
<li class="header-navigation-item navigation-item-primary">
<a class="navigation-link-primary" href="{{urls.auth.logout}}">{{lang 'account_general.log_out'}}</a>
</li>
{{else}}
<li class="header-navigation-item navigation-item-primary">
<a class="navigation-link-primary" href="{{urls.auth.login}}">{{lang 'account_general.log_in'}}</a>
</li>
{{#if settings.account_creation_enabled}}
<li class="header-navigation-item navigation-item-primary">
<a class="navigation-link-primary" href="{{urls.auth.create_account}}">{{lang 'account_general.sign_up'}}</a>
</li>
{{/if}}
{{/if}}

Selenium - How to click on this span?

I've tried using cssSelector and xpath. I can't use class=chips__text as it is not unique. How can I click on the span with text Nou?
<ul id="targetparam17" class="chipschoice fleft">
<li class="hidden">
<a href="#" class="is-selected">
<span class="chips__text">Alege</span>
<span class="value"></span>
</a>
</li>
<li class="">
<a href="#" class="">
<span class="chips__text">Utilizat</span>
<span class="value">used</span>
</a>
</li>
<li class="">
<a href="#" class="">
<span class="chips__text">Nou</span>
<span class="value">new</span>
</a>
</li>
</ul>
Find the element with respect to the desired text i.e. "Nou" and then click on it. xpath for it is //span[text()='Nou']. In case if you with to use different texts to click on different spans, you can manipulate the xpath using string manipulation techniques. Hope it helps :)
ExpectedConditions.elementToBeClickable means to selenium to be clickable is that it is visible & enabled. See Here
So you should check whether webElement isDisplayed() & isEnabled().
Or alternatively you can use ExpectedConditions.visibilityOf(WebElement)
I've used //span[contains(.,'Nou')] and it works perfectly
Try below xpath :
driver.find_element_by_xpath("//ul[#id='targetparam17']//li//a//span[contains(.,'Nou')")

XPath to select following-sibling

This is the code that I currently have:
<div>
<ul class="nav nav-pills nav-stacked">
<li>
<li>
<li>
<li>
<li>
<section>
<span name="merchant">ABZ</span>
</section>
<section>
<span class="glyphicon glyphicon-pencil" name="edit"></span>
<span class="glyphicon glyphicon-remove" name="delete"></span>
</section>
</li>
<li>
<li>
<li>
<li>
</ul>
<div class="add-item bottom" name="new-merchant">
</div>
I have tried the following:
xpath=//span[contains(.,'ABZ')]/following-sibling::section/span[#name='edit']
xpath=//span[contains(.,'ABZ')]/following-sibling::span[1]
I am using selenium, and I want it to click on the edit button that is right after the ABZ span.
This xpath worked for me in Chrome, using your html:
//span[contains(text(), 'ABZ')]/../following-sibling::section/span[#name='edit']
Edit
The .. means to go up a level. The .. takes the selector from span to section. Then the following-sibling finds the section after the parent section of your matching span.
Your original selector was matching span, then looking for a following-sibling to span.
Adding to the answer above, both the expressions below will work well.
//span[contains(text(), 'ABZ')]/following::section/span[#name='edit']
OR
//span[contains(text(), 'ABZ')]/../following-sibling::section/span[#name='edit']
Notably, the axis following will pick each node following the context node while the axis following-sibling will only pick the sibling nodes to the context node.

Find titles of Anchor tags using Selenium

I need to find number of anchor tags and their titles in code mentioned below. I am using web driver, java, Selenium.
<div>
<div>
<div>
<div>
<ul>
<li>
<a></a>
</li>
<li>
<a></a>
</li>
</ul>
<ul>
<li>
<a></a>
</li>
<li>
<a></a>
</li>
</ul>
<ul>
<li>
<a></a>
</li>
<li>
<a></a>
</li>
</ul>
</div>
</div>
</div>
</div>
What will be the best way to find it?
Thanks in advance.
I assume that by 'title' you meant the text between the anchor tags.
Use the following code:-
//find the div tag
WebElement divTag = driver.findElement(By.xpath("//div/div/div/div"));
//find all the a tags in the div tag
List<WebElement> allAnchors = divTag.findElements(By.tagName("a"));
//print number of anchor tag
System.out.println("Number of Anchor tags = " + allAnchors.size());
//print text within each anchor tag
int count=0
For(WebElement anchor : allAnchors) {
System.out.println("Text within anchor"+ (++count) + "="+ anchor.getText());
}
Let me know if this helps you.