I do this in my controller (Time.now - 5.seconds).iso8601 and pass that to my front end which is built in Vue.
The time my controller returns is in this format:
2021-03-13T00:17:32.602Z
On the front end I am displaying the humanized form of the above date like this:
a few seconds ago
In my Vue front end, things look great BUT, I continue to get this error:
Could not build a valid `moment` object from input.
The vue code that displays this is:
{{ item.last_synced | moment("from") }}
What can I do to get rid of that error? Unfortunately I cannot ignore, as this is for an app, and the marketplace will reject me app if it has any warnings.
Related
def linkdin_login(company_name,username,password):
driver.get('https://linkedin.com/')
driver.find_element(By.XPATH,'//*[#id="session_key"]').send_keys(username)
driver.find_element(By.XPATH,'//*[#id="session_password"]').send_keys(password)
driver.find_element(By.XPATH,"//button[#class='sign-in-form__submit-button']").click()
#def company_info(company_name):
element = driver.find_element(By.CSS_SELECTOR,"#global-nav-typeahead > input")
element.send_keys(company_name)
element.send_keys(Keys.ENTER)
driver.implicitly_wait(10) # seconds
driver.get(driver.find_element(By.CSS_SELECTOR,".search-nec__hero-kcard-v2 > a:nth-child(1)").get_attribute("href"))
driver.implicitly_wait(10)
people()
by the above code i am logging into LinkedIn and fetching the LinkedIn page of the some companies after getting the page I am trying to get the employee data by using people function show below
def people():
driver.implicitly_wait(10)
driver.get(driver.find_element(By.XPATH,"/html/body/div[5]/div[3]/div/div[2]/div/div[2]/main/div[1]/section/div/div[2]/div[1]/div[2]/div/a").get_attribute("href"))
driver.implicitly_wait(10)
people = driver.find_element(By.XPATH,"/html/body/div[4]/div[3]/div[2]/div/div[1]/main/div/div/div[2]/div/ul")
people_data = people.find_elements(By.TAG_NAME,"li")
for i in people_data:
print(i.text)
in this function i am trying to access the link to employees data
that is where the problem lies
the line 2 of people function i trying to get the link the problem is due to some reason sometimes i am getting the link(not to frequently!!) but most of the time i am getting the error saying Xpath not found
i didn't know how to attach a html page so i am attaching the link
([https://www.linkedin.com/company/google/](https://www.stackoverflow.com/)
1. I tried implicit wait assuming that the program is trying to access the Xpath during loading of the page
For context, I'm someone with zero experience in Ruby - I just asked my Senior Dev to copy-paste me some of his Ruby code so I could try to work with some APIs that he ended up putting off because he was too busy.
So I'm using an API wrapper called zoho_hub, used as a wrapper for Zoho APIs (https://github.com/rikas/zoho_hub/blob/master/README.md).
My IDE is VSCode.
I execute the entire length of the code, and I'm faced with this:
[Done] exited with code=0 in 1.26 seconds
The API is supposed to return a paginated list of records, but I don't see anything outputted in VSCode, despite the fact that no error is being reflected. The last 2 lines of my code are:
ZohoHub.connection.get 'Leads'
p "testing"
I use the dummy string "testing" to make sure that it's being executed up till the very end, and it does get printed.
This has been baffling me for hours now - is my response actually being outputted somewhere, and I just can't see it??
Ruby does not print anything unless you tell it to. For debugging there is a pretty printing method available called pp, which is decent for trying to print structured data.
In this case, if you want to output the records that your get method returns, you would do:
pp ZohoHub.connection.get 'Leads'
To get the next page you can look at the source code, and you will see the get request has an additional Hash parameter.
def get(path, params = {})
Then you have to read the Zoho API documentation for get, and you will see that the page is requested using the page param.
Therefore we can finally piece it together:
pp ZohoHub.connection.get('Leads', page: NNN)
Where NNN is the number of the page you want to request.
Here's the super short version of what's happening, as far as I can tell. Debugging this has been a pain, and I'm not sure if this is a Laravel issue or a Vue.js issue (leaning toward Vue.js). Here goes...
I'm using a LengthAwarePaginator object to retrieve data to pass to a Vue.js component as a property. (This is unorthodox, and I plan to convert it to a fetch() method in the component when I have a proper API set up.)
<my-component :items="{{ $paginator->toJson() }}"></my-component>
When my $paginator data contains an item with a string field that contains " -- e.g. Plumber cut pipe 4" from end -- Vue.js completely fails to render my component.
However, if instead of " the field uses a raw ", everything works just fine -- e.g. Plumber cut pipe 4" from end.
I was alerted to this issue by a Vue.js parse error: avoid using JavaScript keyword as property name: "for" in expression .... I believe I received this error because of subsequently broken syntax that made a string use of 'for' look like a property name.
It's almost like Vue.js is double-converting the resulting " to " when it reads the property, and the resulting extra " turns string data into a property name. This makes no sense though, since the raw " allows proper parsing.
My work-around, while I try to understand why this is even broken at all, has been to assign my property like this:
<my-component :items="{{ $paginator->toJson(JSON_HEX_AMP) }}"></my-component>
Does anyone understand why this is happening? Why is this an unsafe string in this context: Plumber cut pipe 4" from end ???
I am using Capybara and getting errors from the finders 'find_field' & 'has_selector'.
I have tried using them like this:
page = visit "http://www.my-url-here.com"
next if page.has_selector?('#divOutStock')
page.find_field('#txtQty').set('9999')
has_selector returns the error: "NoMethodError: undefined method `has_selector?' for {"status"=>"success"}:Hash"
find_field cannot find the field. (It is present on the page and is not a hidden field.)
I have also tried using fill_in to set the field value, that doesn't work either.
How can I get this to work with Capybara?
You have a couple of issues in your code
page is just an alias for Capybara.current_session. If you assign to it you're creating a local variable and it's no longer a session
find_field takes a locator - http://www.rubydoc.info/gems/capybara/Capybara/Node/Finders#find_field-instance_method - which will be matched against the id, name, or label text. It does not take a CSS selector
Your code should be
page.visit "http://www.my-url-here.com"
next if page.has_selector?('#divOutStock')
page.find_field('txtQty').set('9999')
and you could rewrite the last line as
page.fill_in('txtQty', with: '9999')
Also you should note that (if using a JS capable driver) has_selector? will wait up to Capybara.default_max_wait_time for the #divOutStock to appear. If it's not usually going to be there and you want to speed things up a bit you could do something like
page.visit "http://www.my-url-here.com"
page.assert_text('Something always on page once loaded') #ensure/wait until page is loaded
next if page.has_selector?('#divOutStock', wait: 0) # check for existence and don't retry
page.fill_in('txtQty', with: '9999')
I've got a tiny Sinatra app running on Heroku, and it has a method that receives a POST and creates a database object with the parameters of the POST.
One of those params is a timestamp of the form "1432565475.000007". I want that as a date & time in the database, so I added a column, then in the method that handles the post I have:
e.time = Time.at params["timestamp"].to_f
The times come out correctly, but the dates are all Jan 1, 2000.
If I run irb at heroku ("heroku run irb") and try the above line of code manually it converts correctly. It's only when it's running inside my server instance that it interprets the calendar date wrong.
So then I created a view that just iterates through the db, converting the original timestamp (I also have that in a column) into dates. The idea being that this is more closely approximating the code that handles the POST:
-MyEvent.all.each do |me|
%p
=Time.at me.timestamp.to_i
And that works perfectly.
Any ideas?