How to remove attribute of a tag in Telegram's instant view API? - api

I have this
<span class="img-fc">
<img src="https://img1.ibxk.com.br/2017/04/12/12095959053024.png?w=700">
<span class="desc">The image desc is here!</span>
</span>
So I used some functions of the API to change the description
<figure>: //span[#class="img-fc"]
<figcaption>: //figure[#class="img-fc"]/span[#class="desc"]
And I get this result in the instant view debug:
> #debug: $body//figure
Debug 1 node:
[0]: <figure class="img-fc"><img src="https://img1.ibxk.com.br/2017/04/12/12095959053024.png?w=700"><figcaption class="desc">The image desc is here!</figcaption></figure>
Instant View successfully generated
But, its not generatig an img with a caption bellow the image.
Here is the result:

First step: convert all <span class="desc"> tag in <span class="img-fc"> tag to <figcaption> tag:
<figcaption>: //span[has-class("img-fc")]//span[has-class("desc")]
Second and final step is convert all <span class="img-fc"> tags to <figure>:
<figure>: //span[has-class("img-fc")]

Related

Unable to get text() node before a specific span using xpath

I'm trying to find the immediate preceding text of an element.
Below is the sample HTML code that I'm working on.
<span class= "platform">
::before
<br>
name
<br>
age
<span class = "highlight">
::before
"Negine"
</span>
</span>
Came up with an XPath:
//span[#class='platform']/text()[following-sibling::span[position() = 1]]
But the XPath is returning both text nodes where as it should return only 'age'.
Have written this text using your provided HTML in the comment section.
Try using this xpath - //span[#class="platform"]/text()[3]

Selector to extract element value of type different tagName

There is String on my web page which looks as "#Account9 Hey Dude". #Account9 is a link, 'Hey Dude' is span. Please help me to create Selector to extract this "#Account9 Hey Dude".
note: Can find something like selenium "normalize-space" method.
#Account9
Hey Dude
To create a selector that extracts the inner text of the provided markup:
<div class=“XYZ123>
<span class="r-18u37iz">
<a href="/Account9" dir="ltr" role="link" data-focusable="true" class=“ABC123”>#Account9 </a>
</span>
</div>
<span class=“ABCxyz123”> :Hey Dude</span
you need to find the first parent of these elements (div class=“XYZ123 and span class=“ABCxyz123”) , specify CSS selector for it and call innerText property.
const targetText = await Selector('<parent_of_these_elements>').innerText;

Puppeteer (1.14.0) unable to find anchor tag by "id" although JQuery can find it

Node v10.15.3 (64-bit)
Puppeteer v1.14.0
Chromium v 75.0.3738.0 (Developer Build) (64-bit)
I am at the very last page of a site automation tool and the last button I need to press (which is actually an anchor tag with an "id" attribute) cannot be found by Puppeteer. The code is:
await page2.click('#____bs');
The error I receive is:
Error: Node is either not visible or not an HTMLElement
The HTML code is here:
<a role="button" ct="Button" rel="tooltip" title="Post"
aria-label="Please Select Post" data-toggle="cso-button" id="____bq"
class="cso-btn cso-btn cso-action cso-corner cso-btn-primary "
href="javascript:void(0)"
data-ctl-options="{'actiontype';:'ACTION','value':'Click'}"
style="display: inline-block;">Post</a>
While in debug mode with this page up, I can use JQuery to find the element easily:
$("#____bq").text()
"Post"
Therefore, why can't Puppeteer find it? Is there an alternate way I could try to click this link?
Could it also be that the control (the anchor) is outside the visible edge of the screen? I wouldn't think that would matter since I'm assuming Puppeteer is looking at the HTML and not the screen itself but doesn't hurt to ask.
Thanks in advance.
UPDATE: Here's the entire HTML that contains the anchor I'm trying to select:
<div class="row split">
<div class="clsFP-expand clsBG-expand cso-hidden cso-cont-50r cso-pad5r">
<span class="cso-pad5-ie">
<a role="button" ct="Button" rel="tooltip" title="Cancel" aria-label="Please Select Cancel" data-toggle="cso-button" id="____bo" class="cso-btn cso-btn cso-action cso-corner cso-btn-grey " href="javascript:void(0)" data-ctl-options="{"actiontype":"ACTION","value":"Click"}" >Cancel</a>
</span>
<span class="cso-pad5-ie">
<a role="button" ct="Button" rel="tooltip" title="Post" aria-label="Please Select Post" data-toggle="cso-button" id="____bs" class="cso-btn cso-btn cso-action cso-corner cso-btn-primary inactive " href="javascript:void(0)" data-ctl-options="" >Post</a>
<a role="button" ct="Button" rel="tooltip" title="Post" aria-label="Please Select Post" data-toggle="cso-button" id="____bq" class="cso-btn cso-btn cso-action cso-corner cso-btn-primary " href="javascript:void(0)" data-ctl-options="{"actiontype":"ACTION","value":"Click"}" >Post</a>
</span>
</div>
</div>
It's not that Puppeteer is not being able to get the element. That's a validation coming from Puppeteer (see https://github.com/GoogleChrome/puppeteer/blob/5ee21d97e796263857b9f3fbeaf63366179d346f/lib/JSHandle.js#L203).
According to the doc:
This method fetches an element with selector, scrolls it into view if needed, and then uses page.mouse to click in the center of the element. If there's no element matching selector, the method throws an error.
That means that Chromium should be able to scroll to that element, and that element should be visible in order to be able to click on it.

I want an another image than the one is the cover image product

i have a issue with a prestahop module, it's Advanced Top Menu.
I a have a submenu with my products and it show the image cover of the product. But, i want to show a another image which is a second image of the product not the cover image.
I sought where can i do that and I find the file here : /themes/at_manor/templates/catalog/_partials/miniatures/product.tpl
A part of the file product.tpl
<a href="{$product.url}" class="thumbnail product-thumbnail">
<img
class="img-fluid"
src = "
{$product.cover.bySize.large_default.url}"
alt = "{if
!empty($product.cover.legend)}{$product.cover.legend}{else}
{$product.name|truncate:30:'...'}{/if}"
data-full-size-image-
url = "{$product.cover.large.url}"
>
{if isset($cfg_product_one_img)
&& $cfg_product_one_img}
<span class="product-
additional" data-idproduct="{$product.id_product}"></span>
{/if}
</a>

Not finding the Correct xpath

I'm trying write a Python script to get some information from Google's products listed on the top right of the screen. (Usual 6 pictures with price and seller)
I am using Python, PhantomJS and Selenium
Doing a google search for "red shoe" I want my script to return the prices. I get stuck in the step where I try to even find the element containing the products. Am I missing something with my xpath?
def getTopSongs(object):
print "Working YETI"
browser = webdriver.PhantomJS('c:/projects/phantomjs/phantomjs.exe')
browser.get('http://google.com/search?q=red+shoe')
time.sleep(5)
title = browser.find_element_by_xpath('//div[contains#class, "pla-unit")]/text()[contains(., "red")]/following::b').text
From Google's webpage I element under a few nested
<div id="rhs">
...
<div class="_Pwb">
<div class="_Ohb">
<div style="width:109px" class="pla-unit">
<div class="_PD">
<div class="pla-unit-img-container">
<div class="_Z5">
<div class="_vT"><a href="http://www.somewebsite.com">
<span class="rhsl4">Nina 'Forbes' Peep Toe Pump <b>Red</b> R...</span>
<span class="rhsg3 rhsl5">Nina 'Forbes' Peep Toe Pum...</span>
<span class="rhsg4">Nina 'Forbes' Peep Toe Pu...</span></a>
</div>
<div class="_QD"><b>$78.95</b></div>
<div class="_mC">
<span class="rhsl4 a">Nordstrom</span>
<span class="rhsg3 rhsl5 a">Nordstrom</span>
<span class="rhsg4 a">Nordstrom</span>
</div>
</div>
*Update:
I added more HTML. In this example I am looking to get the text from ($78.95) annd (Norstrom)
*Update
To clarify,
<div id="rhs">
is an unique element
There are however multiple (6) elements of:
<div style="width:109px" class="pla-unit">
The elements under each category have the same name and follow the same structure and substructures
ie, there are 6
<div class="_PD">
<div class="pla-unit-img-container">
<div class="_Z5">
<div class="_vD">
<div class="_QD">
<div class="_mC">
and so on.
The main objective is to get all of the elements but for purposes of debugging I was asking help to get the first one.
The xpath for a price unit using XPathChecker on Firefox is:
id('rhs_block')/x:div[1]/x:div/x:div/x:div/x:div[1]/x:div[1]/x:div[2]/x:div[2]/x:b
You can use ancestor:: to go back up then following-sibling:: to get elements at the same level that follow it.
I haven't tried this but give it a shot:
title = browser.find_element_by_xpath('//div[contains#class, "pla-unit")]/text()[contains(., "red")]/ancestor::div/following-sibling::div[1]').text
Then to get to your div class ='mC' you just change:
following-sibling::div[1]
to
following-sibling::div[2]
and get the text from the spans under that.