SeleniumError in vba - vba

I am trying to take a Selenium test and convert it into excel VBA code.
I have come to a Selenium error when I have tried to do my code [I am pretty much useless here:( ]
Could I get guidance on the vba error?
Secondly any suggestions on how to do the vba code
The error is as attached VBA Error
The vba code that I have at the moment is
Sub Buy()
Dim driver As New Selenium.ChromeDriver
Dim count As Long
Sheets("Input").Activate
Set driver = CreateObject("Selenium.ChromeDriver")
count = 1
' Code assumes all VAT numbers in Column A are valid
' No error checking is included here in case they are not
'
While (Len(Range("A" & count)) > 0)
driver.Get "https://www.mycode.com.au/Portfolio/Details/12635600"
driver.FindElementById("New Buy").Click
driver.FindElementById("New Buy").Click
driver.FindElement(By.ID("SecurityCode")).SendKeys ("JBH")
driver.FindElement(By.ID("NumberOfShares")).SendKeys ("500")
driver.FindElement(By.ID("SharePrice")).SendKeys ("20")
driver.FindElement(By.ID("Fees")).SendKeys ("9.5")
driver.FindElement(By.ID("Submit")).Click
' Uncomment the next line if you need to introduce a delay in the browser
' to allow it to load the results page
'Driver.Wait 1000
Range("B" & count) = driver.FindElementByXPath("//table/tbody/tr[6]/td[2]").Text
count = count + 1
Wend
driver.Quit
End Sub
The Selenium IDE file that I am trying to emulate is
{
"id": "d4a3caeb-1fd0-4a30-8c17-d69d7a1b6e36",
"version": "2.0",
"name": "Test 10",
"url": "https://www.mycode.com.au",
"tests": [{
"id": "880b98ad-ce57-416d-abab-d5b9eac336cf",
"name": "Test 10",
"commands": [{
"id": "9c84d13e-49f7-4e1e-8e6b-45a1b9654a87",
"comment": "",
"command": "open",
"target": "/Portfolio/Details/126356",
"targets": [],
"value": ""
}, {
"id": "57eb50bf-f996-4e20-b9c2-15f476e43324",
"comment": "",
"command": "setWindowSize",
"target": "1552x840",
"targets": [],
"value": ""
}, {
"id": "b627d6f1-2d7a-4b92-bdf6-80c400f787e5",
"comment": "",
"command": "click",
"target": "linkText=New Buy",
"targets": [
["linkText=New Buy", "linkText"],
["css=.btn-order-buy", "css:finder"],
["xpath=(//a[contains(text(),'New Buy')])[2]", "xpath:link"],
["xpath=//a[#onclick='return false;']", "xpath:attributes"],
["xpath=//div[#id='active-tab']/div[3]/div[2]/div/div/div/div/a", "xpath:idRelative"],
["xpath=(//a[contains(#href, '/PortfolioTransaction/NewBuy?portfolioId=12635600')])[3]", "xpath:href"],
["xpath=//div[2]/div/div/div/div/a", "xpath:position"]
],
"value": ""
}, {
"id": "f4d72730-3eaa-44e7-85c3-1c63a79032bc",
"comment": "",
"command": "type",
"target": "css=div:nth-child(3) > #SecurityCode",
"targets": [
["css=div:nth-child(3) > #SecurityCode", "css:finder"],
["xpath=(//input[#id='SecurityCode'])[4]", "xpath:attributes"],
["xpath=//div[#id='page-trade-details']/div/fieldset/div/div[3]/input", "xpath:idRelative"],
["xpath=//fieldset/div/div[3]/input", "xpath:position"]
],
"value": "JBH"
}, {
"id": "2a6976b9-7364-4dab-bbaf-ebdc214cbe2c",
"comment": "",
"command": "type",
"target": "id=NumberOfShares",
"targets": [
["id=NumberOfShares", "id"],
["name=NumberOfShares", "name"],
["css=#NumberOfShares", "css:finder"],
["xpath=//input[#id='NumberOfShares']", "xpath:attributes"],
["xpath=//div[#id='page-trade-details']/div/fieldset/div/div[4]/div[2]/input", "xpath:idRelative"],
["xpath=//div[4]/div[2]/input", "xpath:position"]
],
"value": "500"
}, {
"id": "1bdbb4a4-221c-4e5f-87d7-3a6e0c9e3ad4",
"comment": "",
"command": "type",
"target": "id=SharePrice",
"targets": [
["id=SharePrice", "id"],
["name=SharePrice", "name"],
["css=#SharePrice", "css:finder"],
["xpath=//input[#id='SharePrice']", "xpath:attributes"],
["xpath=//div[#id='page-trade-details']/div/fieldset/div/div[4]/div[3]/input", "xpath:idRelative"],
["xpath=//div[4]/div[3]/input", "xpath:position"]
],
"value": "20"
}, {
"id": "e8a85e6f-30bc-4a9f-a13e-bc591ac24d0b",
"comment": "",
"command": "type",
"target": "id=Fees",
"targets": [
["id=Fees", "id"],
["name=Fees", "name"],
["css=#Fees", "css:finder"],
["xpath=//input[#id='Fees']", "xpath:attributes"],
["xpath=//div[#id='page-trade-details']/div/fieldset/div/div[4]/div[4]/input", "xpath:idRelative"],
["xpath=//div[4]/div[4]/input", "xpath:position"]
],
"value": "9.5"
}, {
"id": "3bbf2177-6e3e-4fa1-a00b-f5eff9ffe553",
"comment": "",
"command": "click",
"target": "css=#page-trade-details #Submit",
"targets": [
["css=#page-trade-details #Submit", "css:finder"],
["xpath=(//input[#id='Submit'])[3]", "xpath:attributes"],
["xpath=//div[#id='page-trade-details']/div[2]/input[2]", "xpath:idRelative"],
["xpath=//div[2]/form/div/div[2]/input[2]", "xpath:position"]
],
"value": ""
}]
}],
"suites": [{
"id": "03623809-e8f4-4f37-a9dc-548b1aba1757",
"name": "Default Suite",
"persistSession": false,
"parallel": false,
"timeout": 300,
"tests": ["880b98ad-ce57-416d-abab-d5b9eac336cf"]
}],
"urls": ["https://www.mycode.com.au/"],
"plugins": []
}

Thanks for your reply.
Firstly, "mixing languages" - can you please be more specific
Secondly "You set up selenium to auto-instantiate but then SET the driver reference with late-binding." - again can you be more specific
My apologies, but my skill level is way off. This is a stand alone project, for myself, to achieve an efficiency outcome re data entry into a webform.
The reference to VAT can be ignored. The code is extracted from a website to give me a start on the vba. VAT is not relevant to my task.
I have sent the output to python as follows
# Generated by Selenium IDE
import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
class TestTest10():
def setup_method(self, method):
self.driver = webdriver.Chrome()
self.vars = {}
def teardown_method(self, method):
self.driver.quit()
def test_test10(self):
self.driver.get("https://www.mywebsite.com.au/Portfolio/Details/12635600")
self.driver.set_window_size(1552, 840)
self.driver.find_element(By.LINK_TEXT, "New Buy").click()
self.driver.find_element(By.CSS_SELECTOR, "div:nth-child(3) > #SecurityCode").send_keys("JBH")
self.driver.find_element(By.ID, "NumberOfShares").send_keys("500")
self.driver.find_element(By.ID, "SharePrice").send_keys("20")
self.driver.find_element(By.ID, "Fees").send_keys("9.5")
self.driver.find_element(By.CSS_SELECTOR, "#page-trade-details #Submit").click()
With this I have modified my vba code as follows:
Sub Buy()
Dim driver As New Selenium.ChromeDriver
Dim count As Long
Sheets("Input").Activate
Set driver = CreateObject("Selenium.ChromeDriver")
count = 1
While (Len(Range("A" & count)) > 0)
driver.Get "https://www.mywebsite.com.au/Portfolio/Details/12635600"
driver.FindElement(By.LINK_TEXT, ("New Buy")).Click
driver.FindElement(By.CSS_SELECTOR, "div:nth-child(3) > #SecurityCode").SendKeys ("JBH")
driver.FindElement(By.ID("NumberOfShares")).SendKeys ("500")
driver.FindElement(By.ID("SharePrice")).SendKeys ("20")
driver.FindElement(By.ID("Fees")).SendKeys ("9.5")
driver.FindElement(By.ID("Submit")).Click
Range("B" & count) = driver.FindElementByXPath("//table/tbody/tr[6]/td[2]").Text
count = count + 1
Wend
driver.Quit
End Sub
On running the vba I get a "Run-time error ‘424’ Object Required". I am unable to work out how to overcome this error.

Related

automating deleting Yahoo emails

I am using Selenium IDE in Firefox to try to delete unread emails from Yahoo mail. We have around 30,000 unread emails and, from what I see, Yahoo will only delete less than 100 each time you delete.
I recorded the steps. When I play them back, the dropdown to select "unread" gets clicked. However, the "unread" doesn't get displayed to click on it.
Also, is there a way to "read" what is displayed on the screen? Sometimes Yahoo asks to confirm the deletion, sometimes it doesn't. Is there a way to conditionally click it if it is there?
The odd thing is that the deleting worked for a while today and then reverted to the "unread" not getting displayed. I find that hard to understand.
Thanks
It's June 2021 and I have a solution:
Took me 10 min to recover 5 years old knowledge. Done via Selenium IDE, easy to install in FFox. then run script/project which I attached.
It's set now to run first delete with Prompt confirmation and then 40 times in the loop without. This is how it works in my security setup and I'm in US, CA.
I imagine that for diff areas or security you might need that confirmation each time on css=.M_1MYwXA:nth-child(3) .D_F Are you Sure button
I overall don't like this Se, dealt with it around 5 years ago, now they change interface and editing capababilites, if any Se guru here he/she can easely make it run smoother I think.
Prerequsites:
Before login into your yahoo in FFox and make it remember your password so script will login automatically, there is no any private data in it or stored passwords. This script will delete mail from default Folder = Inbox, make sure that upon login you're there.
Store code below as ddd.side (extension for IDE)
Then you can watch 3min demo how to install IDE, open and run project.
All steps setup to run with to handle delays, but still it's not a bulletproof, in my case I had to restart FF couple of times. Sometime it just doesn't open base url on first step.
I kept it running for couple of hours and it's DONE. 54000 emails of my wife gone.
I don't think I can attachd this file, so trying to paste,
LEt me know. This script works fine as of June 30 2021, yahoo guys don't sleep so it might be different overtime.
{
"id": "adc727d1-40c6-439d-8702-8f97739c8f44",
"version": "2.0",
"name": "X",
"url": "https://mail.yahoo.com/",
"tests": [{
"id": "ffe439e1-39aa-4114-95f9-14b5cee731dd",
"name": "X",
"commands": [{
"id": "5f61ee21-9745-485e-b113-d1515783dc68",
"comment": "",
"command": "open",
"target": "/",
"targets": [],
"value": ""
}, {
"id": "5d019986-41d9-451a-a328-2681a6d3f439",
"comment": "",
"command": "times",
"target": "40",
"targets": [],
"value": ""
}, {
"id": "89048b9d-1e3c-4e56-b8c7-17a9fe431233",
"comment": "",
"command": "click",
"target": "css=.G_e > .D_F .D_F",
"targets": [
["css=.G_e > .D_F .D_F", "css:finder"],
["xpath=//div[#id='mail-app-component']/div/div/div/div/div/div/div/ul/li/span/button/span", "xpath:idRelative"],
["xpath=//span/button/span", "xpath:position"]
],
"value": ""
}, {
"id": "2a5a4320-d12e-43ef-8f13-ea340c3062a3",
"comment": "",
"command": "pause",
"target": "3000",
"targets": [],
"value": ""
}, {
"id": "af49e7c3-6db0-4236-aa1f-93d94f2acf5c",
"comment": "",
"command": "click",
"target": "css=.M_1MYwXA:nth-child(3) .D_F",
"targets": [
["css=.M_1MYwXA:nth-child(3) .D_F", "css:finder"],
["xpath=//div[#id='mail-app-component']/div/div/div/div/div[2]/div/div[3]/button/span", "xpath:idRelative"],
["xpath=//div[3]/button/span", "xpath:position"],
["xpath=//span[contains(.,'Delete')]", "xpath:innerText"]
],
"value": ""
}, {
"id": "5c463aa8-4782-473e-876c-73921aa75612",
"comment": "",
"command": "pause",
"target": "1000",
"targets": [],
"value": ""
}, {
"id": "b089bb86-60f4-43ee-8031-e5ac930f2f71",
"comment": "",
"command": "click",
"target": "css=.G_e > .D_F .D_F",
"targets": [],
"value": ""
}, {
"id": "3731ebc1-a0c9-46ac-8d7d-c56a2cf3b72a",
"comment": "",
"command": "click",
"target": "css=.M_1MYwXA:nth-child(3) .D_F",
"targets": [
["css=.M_6LEV", "css:finder"],
["xpath=(//button[#type='button'])[192]", "xpath:attributes"],
["xpath=//div[#id='modal-outer']/div/div/div/div[4]/button", "xpath:idRelative"],
["xpath=//div[7]/div/div/div/div/div[4]/button", "xpath:position"],
["xpath=//button[contains(.,'OK')]", "xpath:innerText"]
],
"value": ""
}, {
"id": "cbb516e3-5c38-4ebe-b6ff-65f0fde58cb6",
"comment": "",
"command": "click",
"target": "css=.M_6LEV",
"targets": [],
"value": ""
}, {
"id": "a5a50691-fe3f-4e2f-8788-cad5f9ef18fc",
"comment": "",
"command": "end",
"target": "",
"targets": [],
"value": ""
}]
}],
"suites": [{
"id": "2f69f4d6-3aad-4a60-a137-15541cf6384a",
"name": "Default Suite",
"persistSession": false,
"parallel": false,
"timeout": 300,
"tests": ["ffe439e1-39aa-4114-95f9-14b5cee731dd"]
}],
"urls": ["https://mail.yahoo.com/"],
"plugins": []
}

Can't select nth element of same class with xpath / selenium IDE

Don't understand why the following loop doesn't work except for nth element with same class fails on the 2nd element (I'm presuming 1st element works because it's also the root in xpath):
{
"Command": "storeEval",
"Target": "$('.className').length",
"Value": "max"
},
{
"Command": "store",
"Target": "1",
"Value": "i"
},
{
"Command": "while",
"Target": "(${i} < ${max})",
"Value": ""
},
{
"Command": "echo",
"Target": "Current value of i = ${i}",
"Value": "i"
},
{
"Command": "storeAttribute",
"Target": "//a[contains(#class, 'className')][${i}]#href",
"Value": "link"
},
{
"Command": "endWhile",
"Target": "",
"Value": ""
}
For debugging, I tried to change ...[${i}] to [2] and it fails with both Kantu & Ranorex Selocity. However, From my reading of xpath / Selenium IDE documentation, this syntax should be correct. Any advice?
PS. For reference, the .className is actually .rf-project-cover__title on the page https://www.behance.net/search?field=132&content=projects&sort=published_date&time=week
I think you want to search, then extract i-th item, so you need brackets:
(//a[contains(#class, 'className')])[${i}]
for example:
(//a[contains(#class, 'rf-project-cover__title')])[2]
returns item with link text my portfolio

How to generate HTML table for test execution summary in Email (Outlook) body

Background:
In our project[selenium-cucumber-java-Mvn based] we have test execution reporting done through- master thoughts Cucumber report (mvn dependency). This Report get generated in the test>target directory and we are sharing this folders Link embed in an email to everyone automatically for reporting. Here recipient has to open this link to see the status. Link looks like-
http://localhost:63342/Automation/TestExecutionReports/02-08-2018/Run-1/cucumber-html-reports/overview-features.html
Question:
Now we have a need to send Execution summary also in the email so that one can see high level status without even drilling through Link.
So we need to insert a Tabular format- with columns -TC Name, Status, Execution Time, Overall Count etc. in email body itself in addition to the above Link.
Can someone plz help me doing this?
Other info:
I don't know much how internally master though works, but it gathers the execution data via a JSON file. And we are generating this report in the onExecutionfinish method of TestNGExecutionListener.
our current report looks like an attached snap.
Our json is contains the following info-
[
{
"line": 1,
"elements": [
{
"before": [
{
"result": {
"duration": 3849355155,
"status": "passed"
},
"match": {
"location": "CucumberHooks.InitBrowser()"
}
}
],
"line": 3,
"name": "Add Account and verify details",
"description": "",
"id": "add-account-and-verify-details;add-account-and-verify-details",
"after": [
{
"result": {
"duration": 129904,
"status": "passed"
},
"match": {
"location": "CucumberHooks.TearDownTest(Scenario)"
}
}
],
"type": "scenario",
"keyword": "Scenario",
"steps": [
{
"result": {
"duration": 13810592966,
"status": "passed"
},
"line": 5,
"name": "I have Logged in to Grid application",
"match": {
"location": "leaseSearchSteps.i_have_Logged_in_to_Grid_application()"
},
"keyword": "Given "
},
{
"result": {
"duration": 4659413417,
"status": "passed"
},
"line": 6,
"name": "I select Accounts and Contacts option from the Homepage",
"match": {
"location": "createAccountSteps.selectAccountsAndContactsOptionFromTheHomepage()"
},
"keyword": "And "
},
{
"result": {
"duration": 3470670155,
"status": "passed"
},
"line": 7,
"name": "Click on Add Account button",
"match": {
"location": "createAccountSteps.clickOnAddAccountButton()"
},
"keyword": "Then "
},
{
"result": {
"duration": 28732919407,
"status": "passed"
},
"line": 8,
"name": "Create Account with Account name as \"Pacific UAT Test Account\"",
"match": {
"arguments": [
{
"val": "Pacific UAT Test Account",
"offset": 37
}
],
"location": "createAccountSteps.createAccountWithAccountName(String)"
},
"keyword": "Then "
},
{
"result": {
"duration": 2243415294,
"status": "passed"
},
"line": 9,
"name": "Click on View button",
"match": {
"location": "createAccountSteps.clickOnViewButton()"
},
"keyword": "Then "
},
{
"result": {
"duration": 121318771,
"status": "passed"
},
"line": 10,
"name": "Verify the newly created Account name",
"match": {
"location": "createAccountSteps.verifyTheNewlyCreatedAccountName()"
},
"keyword": "Then "
}
],
"tags": [
{
"line": 2,
"name": "#Test"
}
]
}
],
"name": "Add Account and verify details",
"description": "",
"id": "add-account-and-verify-details",
"keyword": "Feature",
"uri": "src/test/resources/cucumber/featureFiles/AU/addAccountAndVerify.feature"
}
]
I dont have code but I think a probable approach can be like below-
First write some code to generate Table Template with its Header, Main Table, Rows and Columns and Footer.
Then insert the Data into this table by reading it from the features.html page you have (as mentioned in url ). You should be able to read data for pass, fail or whatever needed from this html web page through standard methods [like- getText()] of Selenium .
In the end get this whole table appended to a StringBuilder and send in email message as bu using setting content of thmlSourceEmbed as text/html..hope this help

Bigcommerce Stencil Common Product Card Model has_options attribute not working

According to the documentation, there is a has_options attribute on the Common Product Card Model that should return a boolean showing whether or not the product has options.
However, this value is returning false for all of my products, even though they have options. For example, if I access the homepage in debug mode via this url:
http://localhost:3000/?debug=context
One of the products under the featured products section is:
{
"id": 114,
"name": "Product Name",
"url": "http://www.example.com/product-url",
"brand": null,
"rating": 5,
"availability": "Usually ships the next business day",
"summary": "Product summary goes here",
"image": {
"data": "https://cdn2.bigcommerce.com/server2100/abcdef/images/stencil/{:size}/products/114/8086/product_image.jpg?c=2",
"alt": ""
},
"date_added": "January 6, 2014",
"qty_in_cart": 0,
"pre_order": false,
"has_options": false,
"show_cart_action": false,
"add_to_wishlist_url": "/wishlist.php?action=add&product_id=114",
"price": {
"without_tax": {
"formatted": "$19.99",
"value": 19.99
},
"rrp_without_tax": {
"formatted": "$24.99",
"value": 24.99
},
"saved": {
"formatted": "$5.00",
"value": 5
},
"tax_label": "Tax"
}
}
As you can see has_options is false. However, this product does have options. Via the control panel, I can see that it has a color swatch option. I can also see this by navigating to the products page in debug mode at http://localhost:3000/product-url?debug=context. As you can see, part of the output contains the options information for that product:
"options": [
{
"id": 498,
"type": "Configurable_PickList_Swatch",
"display_name": "Color",
"required": true,
"condition": true,
"values": [
{
"label": "Powder Coat Black",
"id": 390,
"data": [
"000000"
],
"selected": false
},
{
"label": "Anodized Aluminum",
"id": 391,
"data": [
"D9D9D9"
],
"selected": false
}
],
"partial": "swatch"
}
],
As you can see, the product does in fact have options, yet the Common Product Card Model for this product shows has_options as false.
Is there some other setting that is effecting the output of has_options? Why would it be showing false for a product that has options?
has_options is used to denote something is purchasable (true) or not (false). This is misleading and documentation will be revised to reflect this.

Cannot access child value on Newtonsoft.Json.Linq.JProperty

I am trying to parse the json values from the following stream:
{"id": "tag:search.xxxxx.com,2005:xxxxxxxxxxx"}
{"body": "acordei (:"}
{"verb": "post"}
{"link": "http://xxxxx.com/rohanaf_/xxxxxxxxxx/xxxxxxxxx"}
{"generator": {
"link": "http://xxxxx.com",
"displayName": "web"
}}
{"postedTime": "2012-03-31T19:23:51.000Z"}
{"provider": {
"link": "http://www.xxxxx.com",
"displayName": "xxxxxx",
"objectType": "service"
}}
{"object": {
"summary": "acordei (:",
"id": "object:search.xxxxxx.com,2005:xxxxxxxxxxxx",
"link": "http://xxxxxxx.com/rohanaf_/statuses/xxxxxxxxxxxx",
"postedTime": "2012-03-31T19:23:51.000Z",
"objectType": "note"
}}
{"actor": {
"summary": "- namorada da #srtameiga fim. ♥",
"twitterTimeZone": "Brasilia",
"friendsCount": 197,
"location": {
"displayName": "Porto Alegre ",
"objectType": "place"
},
"link": "http://www.xxxxxxxxxx.com/rohanaf_",
"postedTime": "2010-03-31T20:12:49.000Z",
"image": "http://a0.twimg.com/profile_images/xxxxxxxxxxx/Foto1436_normal.jpg",
"links": [
{
"rel": "me",
"href": null
}
],
"listedCount": 3,
"id": "id:xxxxxxxxxxx.com:xxxxxxxxx",
"languages": [
"pt"
],
"utcOffset": "-10800",
"followersCount": 347,
"preferredUsername": "rohanaf_",
"displayName": ", feia ;$",
"statusesCount": 48412,
"objectType": "person"
}}
{
"xxxxxx_entities": {
"urls": [],
"hashtags": [],
"user_mentions": []
}}
{"objectType": "activity"}
{"source": {
"language": {
"value": "fr"
},
"matching_rules": [
{
"value": "lang:fr",
"tag": null
}
],
}}
I tried the following options using JSON.NET and works mostly but missing a couple of fields (source: and all its children including their children). ("source")("matching_rules")("tag") ..etc
Dim results as List(Of JToken) = jobj.Children().ToList
For each item as JProperty In results
item.CreateReader()
If item.name ="id" then
id = item.value
End If
If item.name ="actor" then
author = item.Value("displayName").ToString
End If
If item.name="source" then
Dim gList as IList(Of JToken)= item("matching_rules").Children.ToList
End If
Next
I am trying to get all the children values for that property name source. Now if I use JsonTextReader I can read through everything but this is tedious and prone to errors. Any suggestions appreciated.
I figured it out
If item.name = "source" then
searchterm = item.last.selecttoken("matching_rules").first.item("value").tostring
End if