xpath specific selection with condition - xpath

this might be simple, but I would like to select everything within <div class="rc-box-citations-body"> under the condition that it must belong to <div class="definitionBox" id="meaning-1-1">, thereby uniquely identifying it. How can I do that with xpath? Thanks.
<div class="definitionIndent">
<div class="definitionNumber">1.a</div>
<div class="definitionIndent">
<div class="definitionBox" id="meaning-1-1">
<span class="textmedium">
<span class="stampNoBorder">text</span>
<span class="definition">text</span>
</span>
</div>
<div class="definitionBox">
<div class="rc-box-citations">
<div class="rc-box-citations-top">
<span class="rc-citations-north-west"> </span>
<span class="rc-citations-north-east"> </span>
</div>
<div class="rc-box-citations-body"><span class="citat">text</span> <a class="sourcepop" href="javascript:void(0);"><span class="source">text</span><span class="popup">text</span></a></div>
<div class="rc-box-citations-bot">
<span class="rc-citations-south-west"> </span>
<span class="rc-citations-south-east"> </span>
</div>
</div>
</div>
</div>
</div>

If I modify your xml slightly, and take under the condition that it must belong to to mean that is a descendant of.... then this xpath works
//div[#class='definitionBox'][#id='meaning-1-2']//div[#class='rc-box-citations-body']
The XML is
<?xml version="1.0" encoding="utf-16"?>
<div class="definitionIndent">
<div class="definitionNumber">1.a</div>
<div class="definitionIndent">
<div class="definitionBox" id="meaning-1-1">
<span class="textmedium">
<span class="stampNoBorder">text</span>
<span class="definition">text</span>
</span>
</div>
<div class="definitionBox" id="meaning-1-2">
<div class="rc-box-citations">
<div class="rc-box-citations-top">
<span class="rc-citations-north-west"></span>
<span class="rc-citations-north-east"></span>
</div>
<div class="rc-box-citations-body">
<span class="citation">text</span>
<a class="sourcepop" href="javascript:void(0);">
<span class="source">text</span>
<span class="popup">text</span>
</a>
</div>
<div class="rc-box-citations-bot">
<span class="rc-citations-south-west"></span>
<span class="rc-citations-south-east"></span>
</div>
</div>
</div>
</div>
</div>
The tool I used is XPathVisualizer:

Related

xpath: How to combine multiple conditions on different axes

I try to extract all links based on these three conditions:
Must be part of <div data-test="cond1">
Must have a <a href="..." class="cond2">
Must not have a <img src="..." class="cond3">
The result should be "/product/1234".
<div data-test="test1">
<div>
<div data-test="cond1">
Link 1
<div class="test4">
<div class="test5">
<div class="test6">
<div class="test7">
<div class="test8">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div data-test="test2">
<div>
<div data-test="cond1">
Link 2
<div class="test4">
<div class="test5">
<div class="test6">
<div class="test7">
<div class="test8">
<img src="bild.jpg" class="cond3">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
I'm able to extract the links with the following xpath query.
//div[starts-with(#data-test,"cond")]/a[starts-with(#class,"cond")]/#href
(I know the first part is not really neccessary. But better safe than sorry.)
But I'm still struggling with excluding the links containing an descendant img tag and how to add it to the query above.
This should do what you want:
//div[#data-test="cond1" and not(.//img[#class="cond3"])]
/a[#class="cond2"]
/#href
/product/1234

Bootstrap dropdown-toggle

The dropdown is not showing, I won’t mind any assistance on what I’m doing wrong.
<div class=“boxOptions”>
<div data-toggle=“dropdown” arial-haspopup=“true” arial-expanded=“false”>
<i class=“fas fa-ellipsis-v”></i>
</div>
<div class=“dropdown-menu”>
<a class=“dropdown-item” href=“#”>Activate</a>
<a class=“dropdown-item” href=“#”>Delete</a>
</div>
</div>
Make it like this.
<div class="boxOptions dropdown">
<div data-toggle="dropdown">
<i class='fas fa-ellipsis-v'></i>
</div>
<div class='dropdown-menu'>
<a class='dropdown-item' href='#'>Activate</a>
<a class='dropdown-item' href='#'>Delete</a>
</div>
</div>
Try this one

How to click on link using Selenium in Ruby on Rails?

HTML code:
<div class="card-body">
<div class="row align-items-center mb-4">
<div class="col">
<h1>Data and Tools</h1>
</div>
</div>
<a href="/reports">
<div class="row my-4 align-items-center clickable">
<div class="col my-3">
<span class="semi-bold">Reports</span>
<div class="stamp-md">
Create, run and schedule reports.
</div>
</div>
<div class="col-1 text-right">
<i class="fas fa-chevron-right gray-light small"></i>
</div>
</div>
</a>
<hr class="inner-divider">
Ruby code:
wait.until { #browser_def.find_element(css: ".card-body > a")}.attribute("href").text("Reports").click()
How can I click link which stands for 'Reports'?
I have found the correct answer for it:
wait.until { #browser_def.find_elements(css: 'a[href$="/reports"] div.clickable').first}.click()

Laravel form Submission confirm box

I am a beginner in Laravel, and was wondering if any way to confirm delete before it go to /delete/{id}?
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading"><h2>List of Records:</h2></div>
</div>
<div class="card">
<div class="card-header">Dashboard</div>
<div class="card-body">
#if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
#endif
<p class="bg-primary">Record ID {{$record->id}}</p>
<p class="bg-success">Respond ID {{$record->col1}}</p>
<p class="bg-info">Start Date {{$record->col2}}</p>
<p class="bg-warning">End Date {{$record->col3}}</p>
<p class="bg-danger">Better Consumer Tools {{$record->col4}}</p>
<p class="bg-primary">More public education {{$record->col5}}</p>
<p class="bg-success">Strengthen energy efficiency {{$record->col6}}</p>
<p class="bg-info">Phase out inefficient stuff {{$record->col7}}</p>
<p class="bg-warning">Demand program {{$record->col8}}</p>
<p class="bg-danger">Lower business needs {{$record->col9}}</p>
<p class="bg-primary">Stronger standards {{$record->col10}}</p>
<p class="bg-success">Created at {{$record->created_at->format('d/m/y H:i')}}</p>
<p class="bg-info">Edit|Delete<p>
<button type="button">Go back to Main</button>
</div>
</div>
</div>
</div>
</div>
#endsection
if I use JavaScript functions, how could the function handle the anchor tag to href route?
use this in your anchor tag
<a onclick="return confirm('Are you sure?')" href="deleteRec/{{$record->id}}">Delete</a>

i want to add bootsnipp slider in codeigniter

Here is my main view page :
the first class: item active ,
and another is only class: item
but i want foreach only class="col-sm-6" with two class item active and item ...
<div class="carousel-inner">
<div class="item active">
<div class="row">
<div class="col-sm-6">
<div class="col-item">
<div class="photo">
<img src="img/a.jpg" />
</div>
<div class="info">
<div class="row">
<div class="price col-md-6">
<h5>title</h5>
<h5 class="price-text-color">
Contact for price</h5>
</div>
<div class="rating hidden-sm col-md-6">
<i class="fa fa-bed"></i> <b>3</b>
<i class="fa fa-bath"></i> <b>2</b>
</div>
</div>
<div class="separator clear-left">
<p class="btn-details">
<i class="fa fa-list"></i>More details</p>
</div>
<div class="clearfix">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="item">
<div class="row">
<div class="col-sm-6">
<div class="col-item">
<div class="photo">
<img src="2.jpg" />
</div>
<div class="info">
<div class="row">
<div class="price col-md-6">
<h5>title</h5>
<h5 class="price-text-color">
Contact for price</h5>
</div>
<div class="rating hidden-sm col-md-6">
<i class="fa fa-bed"></i> <b>5</b>
<i class="fa fa-bath"></i> <b>3</b>
</div>
</div>
<div class="separator clear-left">
<p class="btn-details">
<i class="fa fa-list"></i>More details</p>
</div>
<div class="clearfix">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
but when i foreach the div one is active class but i want one div is active but another is not . actually i want to foreach col-sm-6 class.. how to do this. first
I assume that you want the following:
for there to be one active item
for each item to contain several col-sm-6 elements, created via a php foreach loop
create item via a php foreach loop
<!-- language: lang-php -->
<?php $active_item = "active" ?>
<?php foreach($itemlist as $item): ?>
<div class="item <?php echo $active_item ?>">
<?php $active_item = "" ?>
<div class="row">
<?php foreach($item as $column): ?>
<div class="col-sm-6">
<!-- insert your logic here for creating your columns in a carousel -->
</div>
<?php endforeach ?>
</div>
</div>
<?php endforeach ?>
$active will append the active class to only the first instance of your carousel items.
I avoided using foreach($array as $key=>$value) and checking the key for whether the item is to be active, as your array may not have numerical keys that begin with 0.

Resources