How to find if there is an element in a div? - python-3.x

I have a list of posts and some of them has reactions, some not. I want to extract the number of reactions of each posts and the problem is that those who doesn't have, there is no HTML code.
I tried to debug using print.
print(len(driver.find_elements_by_xpath("//div[#class='occludable-update ember-view']")))
-----
Output: 4 - This is good, because I have 4 divs
print(len(driver.find_elements_by_xpath("//span[#class='v-align-middle social-details-social-counts__reactions-count']"))
----
Output:2 - This is good, because I have 2 posts that got reactions
When I tried to find if a posts got reactions,
print(len(driver.find_elements_by_xpath("//div[#class='occludable-update ember-view']")[1].find_elements_by_xpath("//span[#class='v-align-middle social-details-social-counts__reactions-count']")))
----
Output: 2 - Why? Because the second div is empty...
HTML CODE
<div class="occludable-update ember-view">
<ul class="social-details-social-counts ">
<li class="social-details-social-counts__reactions social-details-social-counts__item ">
<button class="social-details-social-counts__count-valuet " aria-label="1 Reaction’ post" type="button">
<img class="reactions-icon social-detail">
<span aria-hidden="true" class="v-align-middle social-details-social-counts__reactions-count">3</span>
</button>
</li></ul>
</div>
<div class="occludable-update ember-view"> this div has no reaction </div>
<div class="occludable-update ember-view"> this div has no reaction </div>
<div class="occludable-update ember-view">
<ul class="social-details-social-counts ">
<li class="social-details-social-counts__reactions social-details-social-counts__item ">
<button class="social-details-social-counts__count-valuet " aria-label="1 Reaction’ post" type="button">
<img class="reactions-icon social-detail">
<span aria-hidden="true" class="v-align-middle social-details-social-counts__reactions-count">3</span>
</button>
</li></ul>
</div>

to locate the continuation element, use .
try below :
driver.find_elements_by_xpath("//div[#class='occludable-update ember-view']")[1].find_elements_by_xpath(".//descendant::span[#class='v-align-middle social-details-social-counts__reactions-count']")

I found the problem. After better documenting myself, I found out that for sub-elements is used .// instead of //
print(len(driver.find_elements_by_xpath("//div[#class='occludable-update ember-view']")[1].find_elements_by_xpath(".//span[#class='v-align-middle social-details-social-counts__reactions-count']")))

Related

access test data after test area in cypress

I have an html code with contains
<div class="form-card">
<h2 class="fs-title" test-data="area_1">
About DigCompEdu
</h2>
<p></p>
<label for="academic_teaching" class="question" test-data="question_1">
<b>1- </b>
</label>
<small id="academic_teachingHelp" class="form-text text-muted">
</small>
<div class="form-check question-form-check ">
<div class="row">
<div class="col-1">
<input class="radio" type="radio" value="0" id="3" name="2" test-data="answer_1" />
</div>
</div>
So, I have h1 with testdata name after that i have a form, this form contains question with multin check radio .. i want to access this check , not by just call ([test-data="answer_2"])
because i have another tips and don't want to check them as this one ,
i did smth like this but it's not working :
cy.get('[test-data="area_1"]~[test-data="answer_2"]').check({force: true})
Any one have another idea ?
It might be the ~ between the selectors, I haven't seen that before.
Does it work with a space between instead?
cy.get('[test-data="area_1"] [test-data="answer_2"]').check({force: true})
If the heading is followed by the form like this
<h2 class="fs-title" test-data="area_1">
About DigCompEdu
</h2>
<div class="form-check question-form-check ">
...
then you would query like this
cy.get('[test-data="area_1"]')
.next('.form-check') // next element on page
.find('[test-data="answer_2"]') // this looks inside '.form-check'
.check({force: true})

need help getting rid of javascript commands in ckeditor

I am currently working on a small project to create a simple social media web app and i am using Laravel. I used CK editor to make the posts in my media , but i found out that,I can use Javascript commands from the editor by going to the source code section.
How can i make it so that the commands don't run but also at the same time have a option to have bold, italic and different fonts and headers.
The following is my code for posting the posts or text;
*<div class="flex justify-center">
<div class="w-9/12 p-3 bg-stale-700 " >
#if ($posts->count())
#foreach ($posts as $post)
<div class="mb-4 p-4 bg-gray-300 rounded " >
<a href="" class="font-bold" > {{$post->user->username}} </a>
<span class=" p-3 text-sm"> {{$post->created_at->toTimeString()}} </span>
{!!$post->body!!}
</div>
#endforeach
{{ $posts->links('pagination::tailwind') }}
#else
There are no posts
#endif
<div>*
The following is the code for ckeditor:
*<form action="{{route('post')}}" method="post" >
#csrf
<textarea name="post"></textarea>
<script>
CKEDITOR.replace( 'post' );
</script>
#error('post')
<p class=" small-text red-200 "> This feild is required </p>
#enderror
<br>
<button class="bg-transparent hover:bg-blue-500 text-blue-700 font-semibold hover:text-white py-2 px-4 border border-blue-500 hover:border-transparent rounded"> post </button>
</form>*
If possible, I am looking for editor like stackoverflow has,
Thank you

Loop through same div' class and grab text using python webdriver

I done all with selenium and webdriver and now not sure how to get text from ALL div class Text3. But also I have problem with div id="TableStart_00023" That changes now and then numbers "TableStart_00023, TableStart_0283 etc.."
Here is HTML PART OF CODE
<div data-reactroot="" id="TableStart_00023">
<ul>
<li class="FirstRow03">
<a class="aClass">
<div class="innerCl">
<div class="Text1"></div>
<div class="Text2"></div>
<div class="Text3">Wanted data</div>
<div class="Text4"></div>
</div>
</a>
</li>
<li class="FirstRow02">
<a class="aClass">
<div class="innerCl">
<div class="Text1"></div>
<div class="Text2"></div>
<div class="Text3">Wanted data 2</div>
<div class="Text4"></div>
</div>
</a>
</li>
</ul>
</div>
Here is Python PART OF CODE what I done
for content in driver.find_elements_by_id('TableStart_00023'):
mytext= content.find_element_by_xpath('.//div[#class="Text3"]').text
print(mytext)
How can I create loop thought all div class Text3 and get text, when ID TableStart changes numbers? What am I doing wrong?
This xpath will return all elements div class Text3 from your table:
//div[starts-with(#id,'TableStart')]//div[#class='Text3']
When you have all this elements (using driver.find_elements_by_xpath) you can get texts from they.

How to show a message if there are no products inside a category with exp:resso store plugin?

I'm using the latest version of EE2 and a plugin called Exp:resso store.
I have products assigned to a category and for the most part all of this is working fine. Below is my code:
<div class="col-md-7">
{exp:channel:categories channel="products" style="linear"}
<section class="section accordion repeater">
<h3>
{category_name}
<div class="icon">
<img src="/assets/local/img/plus-icon.jpg" alt="">
</div>
</h3>
<div class="accordion-content">
{exp:store:search orderby="title" sort="asc" category="{category_id}"}
{exp:store:product entry_id="{entry_id}"}
<p class="accordion-download">
{title} - {price}
<span><img src="/assets/local/img/add-to-cart.jpg" alt="">Add to cart</span>
</p>
{/exp:store:product}
{/exp:store:search}
</div>
</section>
{/exp:channel:categories}
</div>
I'm trying to find a way to show a No products exist message if the category doesn't have anything inside of it. I've tried using {count}, {total_results} & {total_rows} to check if there aren't any products. Problem is everything I try is obviously wrong because nothing gets output :/
Thanks in advance
The store search tag is a wrapper for the channel entries tag pair so you would need to use the {if no_results} tag pair.
<div class="col-md-7">
{exp:channel:categories channel="products" style="linear"}
<section class="section accordion repeater">
<h3>
{category_name}
<div class="icon">
<img src="/assets/local/img/plus-icon.jpg" alt="">
</div>
</h3>
<div class="accordion-content">
{exp:store:search orderby="title" sort="asc" category="{category_id}"}
{exp:store:product entry_id="{entry_id}"}
<p class="accordion-download">
{title} - {price}
<span><img src="/assets/local/img/add-to-cart.jpg" alt="">Add to cart</span>
</p>
{/exp:store:product}
{if no_results}
There are no products
{/if}
{/exp:store:search}
</div>
</section>
{/exp:channel:categories}
</div>
Should also be mentioned if you are not creating a form for the to add the products to the cart you could use the {store_field_short_name:price} variable to reduce the number of queries on your page. Most store things such as sku, weight, measurements can all be access by using the field short name followed by :variable

Error in Expression Engine Embed

I have a site I'm working on at the moment, in which I have a sidebar displaying the 10 most recent posts (titles as links). I'm calling this in with the Embed function.
Though when I am looking on the individual post itself, the list only displays the post title that I'm on.
My embedded code calls all 10 of the recent posts in a exp:channels entry normal way.
Is there something I've done wrong? Below is the code for the main blog page:
{embed="embeds/html_header"}
<!-- content -->
{embed="embeds/html_blog_top"}
<div class="container">
<div class="row">
{embed="embeds/html_blog_sidebar"}
{exp:channel:entries channel="blog" limit="1"}
<div class="span8">
<article>
<header class="postHeader">
<div class="row-fluid">
<div class="span3 postDate">{entry_date format="%d"}<span>{entry_date format="%F"}</span></div>
<div class="span9 postPic">
<div class="imgWrapper">
{blog_image}
</div>
</div>
</div>
</header>
<div class="row">
<section class="span6 offset2">
<h2>{title}</h2>
<p>{full_entry}</p>
<p><span class='st_sharethis' displayText='ShareThis'></span>
<span class='st_facebook' displayText='Facebook'></span>
<span class='st_twitter' displayText='Tweet'></span>
</p>
</section>
</div>
</article>
</div>
{/exp:channel:entries}
</div>
</div>
</section>
<!-- footer -->
{embed="embeds/html_footer"}
This is the sidebar embed:
<aside class="span4" style="float:right;">
<section class="widget search clearfix">
<h3>news</h3>
<p>
{exp:channel:entries channel="blog" limit="10" orderby="date"}
{title}<br>
{/exp:channel:entries}
</p>
</section>
<section class="widget">
<h3>Archives</h3>
<ul>
<li>
{exp:channel:month_links channel="blog"}
{month} {year}<br>
{/exp:channel:month_links}
</li>
</ul>
</section>
</aside>
Its just the bit with the news section that I can't seem to get as a full list on the individual page.
Add dynamic="no" to your embed entries loop and you should be good.
Also, if you want answers on ExpressionEngine questions more quickly, try posting to expressionengine.stackexchange.com

Resources