Excel VBA using Selenium - click on href link - excel

I want to Click on href "add_record.php" by VBA Excel Selenium.
Inspect of Targeted site:
<li class="active">
<i class="fa fa-dashboard"></i><span>Dashboard</span></li>
<li class=""><i class="fa fa-link"></i> <span>Add New Record</span></li>
<li class=""><i class="fa fa-link"></i> <span>Add Record from SRF Portal</span></li>
<li class=""><i class="fa fa-link"></i> <span>List/Edit/Followup</span></li>
<a href="#">

Just to click this element use css selector. * means finding any text as specified after =.
driver.findElementByCssSelector("a[href*=add_record]").Click

Related

Selenium - How to determine the value on click (findElement)?

If I have a header on HTML like these:
<li class="nav-item px-1 pt-1">
<a class="nav-link" href="http://localhost/ciblog/">Home</a>
</li>
<li class="nav-item px-1 pt-1">
<a class="nav-link" href="http://localhost/ciblog/Book">Book</a>
</li>
<li class="nav-item px-1 pt-1">
<a class="nav-link" href="http://localhost/ciblog/TestCreate">Create</a>
</li>
and I want to click on "Book", how do it?
Here's what I tried:
await driver.findElement(By.css('a.nav-link')).click();
and I'm understand that won't work because all of them have nav-link class, how do I call the specific value of book? on Selenium IDE you can just input value = Book
You can locate it with XPath:
await driver.findElement(By.xpath("//a[contains(text(),'Book')]")).click();
Or with css selector
await driver.findElement(By.css("a[href*='Book']")).click();
I would say to go ahead with linkText :
await driver.findElement(By.linkText("Book")).click();

How to click href in VBA Excel

I have an issue to click link <a href below and That Link is Dynamic, here the script that I've made :
Set Menu_KKPTs = HTMLdoc.getElementsByTagName("a")
For Each Menu_KKPT In Menu_KKPTs
Menu_KKPT(17).Click
Next Menu_KKPT
and the HTML Code:
<li class="menu-item" jeniswp="">
<div>KKP</div>
<a href="//index.php?r=awp/awpargp/kkpt&n=eNpjYGBgEmEWZMkrKC8Q5Dc0MTEws7S0MLM0NDUwMBBkKckoy">
<i class="icon-doc"></i>
<span class="title">
</span>
</a>
</li>
Thanks for the help!

linking on bootstrap dropdown not working

<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="bags" id="navbarDropdown3" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
More <i class="fas fa-angle-down ml-3"></i></a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown3">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
here is the code for dropdown
.dropdown-toggle::after {
display: none;
}
.dropdown:hover > .dropdown-menu {
display: block;
}
.dropdown > .dropdown-toggle:active {
pointer-events: none;
}
this is the css for displaying dropdown on hover
clicking on the link doesnt navigate to the page...
i am using express as the backend n typing the link in the navbar works but not clicking the link..
i tried adding data-target but also doesnt seems to work..
i treid setting pointer-event to auto but tat also doesnt deems to work..
Try using data-hover="dropdown" aria-haspopup="true" aria-expanded="false"
<li class="nav-item dropdown" style="cursor:pointer">
<a class="nav-link dropdown-toggle" id="navbarDropdown3" data-hover="dropdown" aria-haspopup="true" aria-expanded="false" href="services.html">SERVICES</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown3">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
This link might be a help.
Bootstrap Dropdown Hover
Wrap the dropdown's trigger and the dropdown menu within .dropdown as it is important. Add data-hover="dropdown" to the main action button or link to activate hover event.
Keypoint is to add data-hover="dropdown"
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" data-hover="dropdown">
Dropdown <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li class="dropdown">
One more dropdown
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li class="dropdown">
One more dropdown
<ul class="dropdown-menu">
...
</ul>
</li>
<li>Something else here</li>
<li>Separated link</li>
</ul>
</li>
<li>Something else here</li>
<li>Separated link</li>
</ul>
</div>

Can segmented-control in Ratchet support multiple rows of control-items?

Can segmented-control in Ratchet support multiple rows of control-items? The code snippet below will make all the items in one row.
<div class="segmented-control">
<a class="control-item active">row1</a>
<a class="control-item">row1</a>
<a class="control-item">row1</a>
<a class="control-item">row1</a>
<a class="control-item">row1</a>
<a class="control-item>row2</a>
<a class="control-item">row2</a>
<a class="control-item">row2</a>
<a class="control-item">row2</a>
<a class="control-item">row2</a>
</div>

How do I select a JS tab in watir-webdriver?

I have a webpage which has tab list, the HTML looks like this for this piece:
<div id="content">
<div class="col span-6">
<div class="section first no-border">
<h2>New Search</h2>
<ul class="tabs clear">
<li id="simple-li" class="current">
<a onclick="switch_search_type('SimpleSearch');; return false;" href="#">Simple</a>
</li>
<li id="structured-li">
<a onclick="redirect_to_search('/search/structured_searches/new'); return false;" href="#">Wizard</a>
</li>
<li id="advanced-li" class="">
</li>
<li id="custom-li" class="">
<a onclick="switch_search_type('ComplexQuerySearch');; return false;" href="#">Custom</a>
</li>
</ul>
<div class="tabbed-panel">
I want to select the "Custom" item in this tab list. I tried multiple things but have failed, some of the things I tried:
browser.li(:id, "custom-li").click
browser.select_list(:id, "custom-li").set("Custom")
browser.link(:xpath, "id('custom-li')/x:a").click
browser.select_list(:id => 'custom-li').select "Custom"
I am new to watir-webdriver. Any feedback and help is greatly appreciated.
Try this:
browser.a(:text => "Custom").click

Resources