I have problem. I have to click the line "in codici prodotto".
<div class="row typeahead">
<div class="col-sm-12 cursor typeahead-row" data-ng-class="{'typeahead-row-selected': view.searchSlots[0].selected}" style="margin-bottom:2px" data-ng-mousedown="searchDocs(model.inputheaderlg)"> " 67D16EA#ABZ "
{{model.inputheaderlg | limitTo: 50}} <span data-ng-if="model.inputheaderlg.length >50">...</span> <span style="color:#bbb"> in informazioni</span> <span class="pull-right"><img style="margin-bottom:3px" alt="vai" src="/opencms/opencms/immagini/rifacimento_nuovo_portale/HP/frecciatype.png"></span>
</div>
<div class="col-sm-12 cursor voffset typeahead-row" data-ng-class="{'typeahead-row-selected': view.searchSlots[1].selected}" data-ng-if="showProduct()" data-ng-mousedown="searchProdotti(model.inputheaderlg)"> " 67D16EA#ABZ "
{{model.inputheaderlg | limitTo: 50}} <span data-ng-if="model.inputheaderlg.length >50">...</span> <span style="color:#bbb"> in prodotti</span> <span class="pull-right"><img style="margin-bottom:3px" alt="vai" src="/opencms/opencms/immagini/rifacimento_nuovo_portale/HP/frecciatype.png"></span>
</div>
<div class="col-sm-12 cursor typeahead-row" data-ng-class="{'typeahead-row-selected': view.searchSlots[2].selected}" data-ng-if="showProductCodes()" data-ng-mousedown="searchCodice(model.inputheaderlg)"> " 67D16EA#ABZ "
{{model.inputheaderlg | limitTo: 50}} <span data-ng-if="model.inputheaderlg.length >50">...</span> <span style="color:#bbb"> in codici prodotto</span> <span class="pull-right"><img style="margin-bottom:3px" alt="vai" src="/opencms/opencms/immagini/rifacimento_nuovo_portale/HP/frecciatype.png"</span>
</div>
</div>
I have tried CSS and with XPATH......
#css
webelem4 <- remote_driver$findElement(using = "css",'#headersearchformlg .ng-scope+ .ng-scope span:nth-child(1)')
webelem4$clickElement
#xpath
webelem4 <- remote_driver$findElement(using = "xpath",'//*
[#id="headersearchformlg"]/fieldset/div/div[3]/div/div[3]')
webelem4$clickElement
.....but I always get the same answer.
Class method definition for method clickElement()
function ()
{
"Click the element."
qpath <- sprintf("%s/session/%s/element/%s/click",
serverURL, sessionInfo[["id"]], elementId)
queryRD(qpath, "POST")
}
<environment: 0x00000248bd0ad708>
Methods used:
"queryRD"
Related
I was trying to scrape this site when I was running into errors due to tags that I thought existed, but did not exist in the scraped html from Bs4.
Site: https://en.thejypshop.com/category/cdlp/59/
I manually verified that the parsed output from Bs4 was giving me a completely different view of the html than when I inspected the site itself; here is a comparison of the two (copied relevant html in the two pastebin links). I also tried scraping with different parsing options such as 'lxml', 'html.parser', etc. but to no avail.
(Bs4 Output): https://pastebin.com/tg4P5DFh
<div class="thumbnail">
<div class="prdImg">
<a href="/product/stray-kids-mini-album-maxident-case-ver/842/category/59/display/2/" name="anchorBoxName_842">
<img alt="" id="eListPrdImage842_2" src="https://cafe24img.poxo.com/jyp3602022/web/product/medium/202210/ca01b08c39232296f482b657be53aa4b.jpg" />
</a>
<span class="wish">
<img alt="Before add to wish list" categoryno="59" class="icon_img ec-product-listwishicon" icon_status="off" individual-set="F" login_status="F" productno="842" src="/web/upload/icon_202204271744355800.png" />
</span>
</div>
<div class="icon">
<div class="promotion"></div>
<div class="button">
<div class="option"></div>
<img alt="Add to cart" class="ec-admin-icon cart" onclick="category_add_basket('842','59', '2', 'A0000', false, '1', 'P0000BGK', 'B', 'T', '20');" src="/web/upload/icon_202204271744303700.png" />
<img alt="View larger image" onclick="zoom('842', '59', '2','', '');" src="//img.echosting.cafe24.com/design/skin/admin/en_US/btn_prd_zoom.gif" style="cursor:pointer" />
</div>
</div>
</div>
(html from Site): https://pastebin.com/2xfi4XTA
<div class="thumbnail">
<div class="prdImg">
<a href="/product/stray-kids-mini-album-maxident-case-ver/842/category/59/display/1/">
<img src="https://cafe24img.poxo.com/jyp3602022/web/product/medium/202210/ca01b08c39232296f482b657be53aa4b.jpg" id="eListPrdImage842_1" alt="">
</a>
</div>
<span class="pro_icon">
<img src="/web/upload/icon_202204271744355800.png" class="icon_img ec-product-listwishicon" alt="Before add to wish list" productno="842" categoryno="59" icon_status="off" login_status="F" individual-set="F">
<img src="/web/upload/icon_202204271744303700.png" onclick="category_add_basket('842','59', '1', 'A0000', false, '1', 'P0000BGK', 'B', 'T', '20');" alt="Add to cart" class="ec-admin-icon cart">
</span>
<span class="soldout_icon"></span>
</div>
Note that the <span class="soldout_icon"></span> tag does not appear in what Bs4 sees, among other things.
My guess as to why this is the case;
I am not using a headless browser, so some websites such as this one might not display the same thing.
There is some JS running in the background that Bs4 does not pick up on
Please let me know if any of my guesses are incorrect and what is actually going on!
Yes, you are right as
the second page is beeing built dynamicaly so you can't get the real html with bs4. Try to use combination of selenium and bs4 to get what you need. Here is a small script that finds some hidden divs and print them out. You should get deeper insight and simulate web surfing to catch the html when the page is fully developed. This one below is still in the process of construction.
import time
from bs4 import BeautifulSoup
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--incognito')
options.add_argument('--headless')
driver = webdriver.Chrome(options = options)
urls = ['https://en.thejypshop.com/category/cdlp/59/', 'https://pastebin.com/2xfi4XTA']
for url in urls:
data = driver.get(url)
time.sleep(1)
pg_html = driver.page_source
pg_html = pg_html.replace('<', '<').replace('>', '>')
soup = BeautifulSoup(pg_html, 'html.parser')
dv = soup.find_all('div', attrs={'class': 'thumbnail'})
dv1 = soup.find_all('span', attrs={'class': 'soldout_icon'})
try:
print(60 * '-')
print(dv[0])
except:
pass
print(60 * '-')
try:
print(dv1[0])
print(60 * '-')
except:
pass
''' R e s u l t :
------------------------------------------------------------
<div class="thumbnail">
<div class="prdImg">
<img alt="" id="eListPrdImage842_2" src="https://cafe24img.poxo.com/jyp3602022/web/product/medium/202210/ca01b08c39232296f482b657be53aa4b.jpg"/>
<span class="wish"><img alt="Before add to wish list" categoryno="59" class="icon_img ec-product-listwishicon" icon_status="off" individual-set="F" login_status="F" productno="842" src="/web/upload/icon_202204271744355800.png"/></span>
</div>
<div class="icon">
<div class="promotion"> </div>
<div class="button">
<div class="option"></div> <img alt="Add to cart" class="ec-admin-icon cart" onclick="category_add_basket('842','59', '2', 'A0000', false, '1', 'P0000BGK', 'B', 'T', '20');" src="/web/upload/icon_202204271744303700.png"/> <img alt="View larger image" onclick="zoom('842', '59', '2','', '');" src="//img.echosting.cafe24.com/design/skin/admin/en_US/btn_prd_zoom.gif" style="cursor:pointer"/> </div>
</div>
</div>
------------------------------------------------------------
<span class="soldout_icon"></span>
------------------------------------------------------------
------------------------------------------------------------
<div class="thumbnail">
</div>
------------------------------------------------------------
<span class="soldout_icon"></span>
------------------------------------------------------------
'''
Regards...
I need to make reactive a class inside a const (exported from a module).
export const messageControls = '
<div id="controls"">
<i id="idcont" class="{{starred}}"></i>
</div>
'
This class belongs to an HTML block who's inserted as innerHTML of a createElement.
var newElement = document.createElement('div');
newElement.id = i._id;
newElement.className = "single_message";
newElement.innerHTML = messageControls;
document.getElementById('conversation_details').appendChild(newElement);
The {{helper}} below is not rendering anything :
starred: function () {
return 'bob';
},
<i id="idcont" class="{{starred}}"></i> gives {{starred}} in plain text
<i id="idcont" class=" ' + {{starred}} + ' "></i> breaks all
Any idea?
Update - full Blaze template as requested
<template name="inbox">
<div class="searchmessages">
<input type="text" name="searchmessages" id="searchmessages" placeholder=" any word / any date">
</div>
<div class="row">
<div class="col-xs-4 l-O list_messages">
<div id="gridreceived" class="gridmessages">
{{#each incoming_all}}
<div id="{{_id}}" class="item {{readornot}}">
<div class="item-content">
<div class="task_inlist">
<div class="task_from">
{{{from}}}
</div>
<div class="task_date">
{{initialdate}}
</div>
<div class="task_subject">
{{{subject}}}
</div>
<div class="task_content">
{{{htmlbody}}}
</div>
</div>
</div>
</div>
{{/each}}
</div>
<div class="grid_nomatch">{{grid_noresult}}</div>
</div>
<div id="conversation_details" class="col-xs-8" media="print">
<!--
here are each selected message details
-->
</div>
</div>
</template>
You're trying to inject spacebars template markup directly into the DOM but meteor-blaze wants to use spacebars to build the DOM. It doesn't watch the DOM for arbitrary changes and then make template substitutions inside of it!
You can instead use Meteor's reactivity to automatically insert new items into the DOM for you based on changes to the underlying data. In your case it looks like you're trying to show the details of a message that's been clicked on. You probably have a template event handler already to catch the click. In that template handler you can set a Session variable which indicates which message is currently selected and then use that Session variable inside the helper that renders the message details.
For example:
<template name="inbox">
<div class="searchmessages">
<input type="text" name="searchmessages" id="searchmessages" placeholder=" any word / any date">
</div>
<div class="row">
<div class="col-xs-4 l-O list_messages">
<div id="gridreceived" class="gridmessages">
{{#each incoming_all}}
<div id="{{_id}}" class="item {{readornot}}">
// render summary of each message
</div>
{{/each}}
</div>
<div class="grid_nomatch">{{grid_noresult}}</div>
{{#with selectedMessage}}
<div id="conversation_details" class="col-xs-8" media="print">
// render selected message details
</div>
{{/with}}
</div>
</template>
Your js:
Template.inbox.events({
'click .item'(ev) {
Session.set('selectedMessageId',this._id);
}
});
Template.inbox.helpers({
selectedMessage() {
return Messages.findOne(Session.get('selectedMessageId'));
}
});
Now to your follow-up question about how to reactively style an element. Let's say your message* object has aisStarredboolean key. In the message detail section we've set the data context using{{#with currentMessage}}` so any key of the current message can be used directly in our spacebars template. Where you are displaying the message details you can do:
<div id="controls"">
<i id="idcont" class="{{#if isStarred}}starred{{/if}}"></i>
</div>
Depending on whether or not the message is starred this will render as class="" or class="starred".
I'd like to be able to automatically fill in the following test. After each phrase you can choose either Eens (I agree) or Oneens (I don't agree). I'm using RSelenium to do this.
Loading my browser and the first phrase poses no problem at all. However, I can't select either the green or red box. I'm using the following code:
choice_xpath <- "//*[contains(.,'Eens')]"
choice <- driver$findElement(using = "xpath",
choice_xpath)
choice$clickElement()
When I execute the code above NULL is returned. Since no 'element not found' error is returned I guess I'm clicking on an element which exists but can't be clicked upon. But I'm at a loss what element to click on if that's the case.
I think this is the html required to understand the problem:
<script type="text/template" id="statements-tpl"></script>
<script type="text/template" id="statement-tpl">
<span class="prev-button"><span><</span></span>
<div class="copy">
<div class="copy-inner">{{ copy }}</div> </div>
<div class="button-wrap">
<div class="button-container">
<div class="button button-1">
</div>
</div>
<div class="button-container">
<div class="button button-0"></div>
</div>
<div class="button-container no-opinion">
<div class="button button-2"></div>
</div>
</div>
<span class="next-button"><span>></span></span>
</script>
<script type="text/template" id="button-tpl">
<div class="button-inner-wrapper">
<div class="button-inner{{ selected ? ' selected' : '' }}">
<div class="prefix">Jouw antwoord:</div>
<div class="copy"> {{% if ( type == 2 ) { %}} Geen mening {{% } else if ( type == 0 ) { %}} Oneens {{% } else { %}} Eens {{% } %}} </div>
<div class="error-tooltip"></div>
</div>
</div>
</script>
Try using below locator to locate appropriate element :-
To locate EENS(Agree) button try as:-
eens <- driver$findElement(using = "css selector", "div.button.button-1")
eens$clickElement()
To locate ONEENS(DisAgree) button try as:-
oneens <- driver$findElement(using = "css selector", "div.button.button-2")
oneens$clickElement()
To locate GEEN MENING(No Opinion) button try as:-
geenmeening <- driver$findElement(using = "css selector", "div.button.button-0")
geenmeening$clickElement()
We have an asp.net hotel room reservation project and I have difficulties in showing the rooms through its status. So if the user will book a room, it will reflect 'In' status in the table. And now, I tried to show the rooms which doesn't have 'In' Status and instead, show the rooms which have 'Out' status. Here is the code that I've been dying to fix:
<%
Dim MyConnNew As OdbcConnection
Dim MyCommNew As OdbcCommand
Dim MyDataReadNew As OdbcDataReader
Dim logic As Integer = 0
MyConnNew = New OdbcConnection("DRIVER={MySQL ODBC 3.51 Driver};Database=hotelsdb;Server=localhost;UID=root;")
MyConnNew.Open()
If MyConnNew.State = 0 Then
MyConnNew.Open()
End If
MyCommNew = New OdbcCommand("select * from hotelbookings where status ='" + "Out" + "'", MyConnNew)
MyDataReadNew = MyCommNew.ExecuteReader()
Dim roomParams As New List(Of Integer)()
While (MyDataReadNew.Read())
If MyDataReadNew.Item("roomid") <> 0 Then
roomParams.Add(MyDataReadNew.Item("roomid"))
logic = 1
End If
End While
Dim roomArray() As Integer = roomParams.ToArray()
If logic <> 0 Then
MyCommNew = New OdbcCommand("select * from hotelrooms", MyConnNew)
MyDataReadNew = MyCommNew.ExecuteReader()
Dim valid As Boolean
valid = False
While (MyDataReadNew.Read())
For i As Integer = 0 To roomArray.Length - 1
If MyDataReadNew.Item("roomid") = roomArray(i) Then
valid = True
End If
Next
If valid <> True Then
%>
<div class="col-xs-12 col-sm-4 col-md-4">
<input type="hidden" value="<%Response.Write(MyDataReadNew.Item("roomid"))%>"/>
<div class="grid wow zoomIn">
<figure class="effect-bubba">
<a href="Rooms.aspx">
<img src="assets/images/<%Response.Write(MyDataReadNew.Item("roomimage"))%>"/>
</a>
</figure>
<div class="text-left">
<input type="hidden" value="<%Response.Write(MyDataReadNew.Item("roomnumber"))%>" />
<ul class="list-unstyled">
<li><h2><%Response.Write(MyDataReadNew.Item("roomtype"))%> Room</h2></li>
<li><b>Adults:</b> Up to 3 adult(s)</li>
<li><b>Children (0-12 yrs old):</b> Free</li>
<li><b>Starting rate per night:</b> <%Response.Write(MyDataReadNew.Item("roomrate"))%> php</li>
<li><a class="btn btn-primary" href="insertreservation.aspx?room_id=<% Response.Write(MyDataReadNew.Item("roomid"))%>" >Reserve</a><br/></li>
</ul>
</div>
</div>
</div>
<nav id="myscroll" class="navbar navbar-default navbar-static top" role="navigation">
<h2>Select Available rooms</h2>
<div class="alert alert-info"><p><b>All rooms have:</b> 40-inch LED HDTV with cable channels• Media panel with HDMI, USB and A/V connectivity• Speaker Phone with iPod dock and FM Stereo• Executive Writing Desk• Complimentary Wi-Fi</p>
</div>
</nav>
<div data-spy="scroll" data-target="#myscroll" data-offset="0" style="height:500px;overflow:auto; position: relative;">
<div class="container">
<%While (MyDataReadNew.Read())%>
<div class="col-xs-12 col-sm-4 col-md-4">
<input type="hidden" value="<%Response.Write(MyDataReadNew.Item("roomid"))%>"/>
<div class="grid wow zoomIn">
<figure class="effect-bubba">
<a href="Rooms.aspx">
<img src="assets/images/<%Response.Write(MyDataReadNew.Item("roomimage"))%>"/>
</a>
</figure>
<div class="text-left">
<input type="hidden" value="<%Response.Write(MyDataReadNew.Item("roomnumber"))%>" />
<ul class="list-unstyled">
<li><h2><%Response.Write(MyDataReadNew.Item("roomtype"))%> Room</h2></li>
<li><b>Adults:</b> Up to 3 adult(s)</li>
<li><b>Children (0-12 yrs old):</b> Free</li>
<li><b>Starting rate per night:</b> <%Response.Write(MyDataReadNew.Item("roomrate"))%> php</li>
<li><a class="btn btn-primary" href="insertreservation.aspx?roomid=<% Response.Write(MyDataReadNew.Item("roomid"))%>" >Reserve</a><br/></li>
</ul>
</div>
</div>
</div>
<%
End While
End If
MyDataReadNew.Close()
MyConnNew.Close()
%>
</div>
Hope you'll help with this :) Thanks
First of all, instead of two queries, you can write:
Select distinct hotelrooms.roomid, hotelrooms.roomimage, hotelrooms.roomtype --other fields here
from hotelbookings
left outer join hotelrooms on hotelrooms.roomid=hotelbookings.roomid
where hotelbookings.status ='Out'
or
select *
from hotelrooms
where roomid in --or 'not in'
(select hotelbookings.roomid
from hotelbookings
where hotelbookings.status ='Out')
Then we need tables structure.
I can't understand why you post
<div class="col-xs-12 col-sm-4 col-md-4">...</div>
maybe it's not related to your question.
Ok, I have this somewhat complex piece of HTML that I have to integrate with. It is a button with a drop down (using aria) and I had to pass in a currency list and be able to select one of the dropdown elements (currency values) and update the button text with the selected value. I write a tiny bit of js and that works well. I use thymeleaf to pass in values to populate and that works well. I also need to read the values that were set from the post to the spring mvc controller but I always get a empty string for the value that I set via js.
here is the javascript
$(".currencyDropdown li a").click(function () {
var selText = $(this).text().trim();
var button = $("#currencyButton");
button.text(selText);
console.log("currency selected is:" + selText);
});
here is the html
<div class="col-sm-9 col-sm-offset-3 col-xs-12 form-row">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle field-small"
type="button"
id="currencyButton"
name="currencyButton"
th:field="${pals.selectedCurrency}"
data-toggle="dropdown"
th:inline="text">
[[${pals.selectedCurrency}]]
<i class="fa fa-caret-down"></i>
</button>
<ul id="currencyDropdown"
class="dropdown-menu currencyDropdown"
role="menu"
aria-labelledby="currencyButton">
<li role="presentation"
th:each="currency:${pals.currencyList}">
<a role="menuitem"
tabindex="-1"
href="#"
th:inline="text">
[[${currency}]]
</a>
</li>
</ul>
</div>
What I am trying to read back in the spring mvc controller is the pals.selectedCurrency value and it is always empty. Something I am missing? I was playing around and tried setting value and field. In reality I want to read the inline text that my js inserts.
I think you must add a th:fragment on you button and change the text of the button via ajax from backing bean from server, not from javascript. It's something like this :
<form th:action="#{/PersonEdit/save(contract=${param.contract})}" th:object="${personBean}"
method="POST" th:if="${param.contract != null}">
... other form components
<div class="form-group">
<label class="col-sm-4 control-label"
th:text="#{person.edit.policy.tfoms}"></label>
<div class="col-sm-8">
<select class="form-control" th:field="*{tfoms}"
onchange="loadInsuranceCompanies()">
<option th:each="t : ${tfomses}"
th:value="${t.uidtfoms}"
th:text="${t.shortName}"
th:selected="${personBean.tfoms != null
and personBean.tfoms.equals(t)}"></option>
</select>
</div>
</div>
<div th:class="${#fields.hasErrors('insuranceCompany')}
? 'form-group has-error' : 'form-group'">
<label class="col-sm-4 control-label"
th:text="#{person.edit.policy.ic}"></label>
<div class="col-sm-8" id="insuranceCompaniesContent">
<select class="form-control" id="insuranceCompany"
name="insuranceCompany"
th:fragment="insuranceCompany">
<option th:each="i : ${insuranceCompanies}"
th:value="${i.uidinsurancecompany}"
th:text="${i.shortName}"
th:selected="${personBean.insuranceCompany != null
and personBean.insuranceCompany.equals(i)}"></option>
</select>
<div th:if="${#fields.hasErrors('insuranceCompany')}"
th:each="err : ${#fields.errors('insuranceCompany')}">
<span class="text-danger" th:text="${err}"></span><br/>
</div>
</div>
</div>
In my case I refreshing one dropdown via another.Then refresh this fragment via ajax on item selection
function loadInsuranceCompanies() {
var url = [[#{/PersonEdit/insuranceCompanies}]];
if ($('#tfoms').val() !== '') {
url = url + '/' + $('#tfoms').val();
}
$("#insuranceCompaniesContent").load(url);
}
I think the trouble can be because you using not a standard select as a dropdown.
Ok, I figured out a relatively simple answer to it. I have to use the html that was provided because of look and feel considerations from the customer.
so what I did was add a hidden input and set that from the java script.
$(".currencyDropdown li a").click(function () {
var selText = $(this).text().trim();
$("#currencyButton").text(selText);
$("#currencySelected").val(selText);
console.log("currency selected is:" + selText);
});
<input type="hidden"
id="currencySelected"
th:field="${pals.selectedCurrency}"/>
<button class="btn btn-default dropdown-toggle field-small"
type="button"
id="currencyButton"
data-toggle="dropdown"
th:inline="text">
[[${pals.selectedCurrency}]]
<i class="fa fa-caret-down"></i>
</button>
<ul id="currencyDropdown"
class="dropdown-menu currencyDropdown"
role="menu"
aria-labelledby="currencyButton">
<li role="presentation"
th:each="currency:${pals.currencyList}">
<a role="menuitem"
tabindex="-1"
href="#"
th:inline="text">
[[${currency}]]
</a>
</li>
</ul>
I see the correct values that were selected for my dropdown on the spring mvc controller and now I can get on with the rest of the stuff.