how to use R-selenium to click a expand list - web-scraping

Right now I'm trying to scraping data from this website. I want to use selenium to click this"View all updates" button. I used SelectorGadget and XPath helper to find the css selector and xpath of it, but both or them failed.
My codes are below:
loadmore <- remDr$findElement(using = 'css selector', ".js-toggle-expand-updates")
loadmore <- remDr$findElement(using = 'xpath', "//*div[#class='js-toggle-expand-updates']")
loadmore$clickElement()

I found the answer myself. The excat class of the button cannot be found through SelectorGadget, it is the first word of class in the code below
<div style="cursor: pointer;" class = "box box-basic type-s pbxxs mbn mtm xs-mts phm xs-phs bg-brighter border-none-a-xs js-toggle-expand-updates">
which is "box"

Related

Protractor can't find button with $ctrl on ng-click

I cannot find buttons that have this $ctrl part with protractor.
Example of a button:
<button class="btn btn-primary ng-scope" ng-click="$ctrl.openProfileModal()" ng-if="$ctrl.admin && $ctrl.networkInfo.scenario !== 'simple_mesh'"
ng-disabled="$ctrl.stats['5G'].full && $ctrl.stats['2G'].full"><i class=""></i>Add virtual AP</button>
The reasonable solution seems to be to search with ng-click:
addVAPButton = element(by.css('[ng-click="$ctrl.openProfileModal()"]'))
But it does not work. I've tried it with various comma combinations, searching by class, by ng-if, by xpath, tried adding id, name, other attributes to this button, but nothing helped Selenium find it. I can find other elements from the page that do not have $ctrl by ng-click, name, id, model, so I suspect that there is something about $ctrl that is not compatible with protractor. Any solutions or workarounds to reach this button?
Protractor version:5.3.0
Angular version: 1.5.11
To find the button with text as Add virtual AP you can use the following line of code :
addVAPButton = element(by.css("button.btn.btn-primary.ng-scope > i"))
Note : As the button is an Angular Element you have to wait for the button to be clickable
Update
As an alternative you can try either of the following options :
addVAPButton = element(by.css("button.btn.btn-primary.ng-scope"))
Or
addVAPButton = element(by.xpath("//button[#class='btn btn-primary ng-scope' and contains(.,'Add virtual AP')]"))
Found a way that works with any selector (css, ng-click, id, name, xpath, whatever):
addVAPButton = $("[ng-click=\"$ctrl.openProfileModal()\"]");
browser.wait(protractor.ExpectedConditions.elementToBeClickable(addVAPButton), 10000).then(function(){
addVAPButton.click();})

Webdriver's click() method not working on a website

I am using WebDriver API to test a webpage and the click() method is not working on a particular webpage.
Neither it is showing any exception nor clicking on the webelement (a link in my case). I tried to find the element using xpath, id and link but the click did not work.
However, when I tried contextClick (i.e. right click) operation on the same link, it worked. Also when I print the text or tagName of the web-element, the text or tagName is displayed perfectly fine on the output screen.
My code:
WebDriver browser=new InternetExplorerDriver();
browser.get("some website");
WebElement linkkk=browser.findElement(By.xpath("//*[#id='topsort']/li[2]/a"));
linkkk.click();
web-page code:
<div class="content">
<div class="blind" style="display: none;"></div>
<ul id="topsort">
<li>something</li>
<li><a class="category_nav_remote_link selected" href="some website">some text</a></li>
</ul>
</div>
</div>
I even used:
Actions action=new Actions(browser);<br/>
action.click(linkkk);
action.perform();
But in vain.
Try below options:
WebElement linkkk=browser.findElement(By.xpath("//*[#id='topsort']/li[2]/a"));
linkkk.click();
//click once again
linkkk.click();
OR - Try by sending ENTER key as below:
linkkk.sendKeys(Keys.ENTER);
OR - First move to that link & then click or send ENTER key
Actions moveTo = new Actions(driver);
moveTo.moveToElement(linkkk).click().perform();
Try using IJavaScriptExecutor to click on the button. It's been very successful on my app.
((IJavaScriptExecutor)_webDriver).ExecuteScript("$(arguments[0].click()",webElement);

Wanting to use an image with text in Html.ActionLink

I am using the following:
<img src="../../Content/Images/lock_16.gif" />
#Html.ActionLink("Register",
"Register",
"Users",
null,
new { title = "Register your ID", rel = "nofollow"
})
What I would like is for the lock image to appear inside of the <a> </a> so it is clickable and not before it. I already use (and change color on hover) of a background image so its not possible for me to use the background-image property to display the image.
Can anyone think of a way that I can set the image so that it will show before the text and still be clickable. Hopefully I can find a way that still allows me to use the MVC Html.ActionLink.
Html helpers in ASP.NET MVC should be used when they simplify writing code, not always. Plain html would go way better in your case
<a href="#Url.Action("Register", "Users")" title="Register Your ID", rel="nofollow">
Register <img src="#Url.Content("~/Content/Images/lock_16.gif")" />
</a>
Note that link address is still generated dynamically, using UrlHelper.Action method. This way, you do not lose link dependency to your route configuration. Also, as Nicholas mentioned, image source should be generated via Url.Content helper.
You may use something like -
#Html.ActionLink("link Name", "Action Method", "Controller", new { style = "background-image:url('.././Images/imageName.png')" },null)
#Html.ActionLink("link Name", "Action Method", "Controller",
new { style = "background-image:url('.././Images/imageName.png')" },
null)

window.open function in HREF TAG not working

I am trying to open popup using window.open finction but somehow it's not working ... well below is the code
string properties = "left=250px, top=245px, width=700px, height=450px,scrollbars=yes, status=yes, resizable=yes";
TableCell cell = new TableCell();
cell.Text = "" + "View Details";
But his is not working. While clicking the anchor tag getting javascript error "Invalid argument". Please tell where am I going wrong?
Thanks,
Rahul
How about using the target attribute on the anchor tag as in: Link text here
Anchor target attribute
_blank – Opens the linked document in a new window or tab
_parent – Opens the linked document in the parent frame
_self – Opens the linked document in the same frame as it was clicked (this is default)
_top – Opens the linked document in the full body of the window
You're doing it wrong. Never put JavaScript into the href attribute. This is how you should do it:
View Details
I added the second argument for window.open (the window identifier) as well, which is probably what was breaking your thing in the first place.
<a href="?i=1" id ="a" runat = "server">
on Page_load()
if (Request.QueryString["i"] == "1")
{
//call ur code here
AreaFootPrint_Click(null,null);
}

How do I add custom hyperlinks to a webpage

I want to add a hyperlink to a social bookmarking site om my webpage which requires me to include the name of the page it is being sent from.
Example of what I am trying to achieve:
Current page is:
http://www.testpage.com/testpage.aspx?test=34
Hyperlink I want to create on the above page:
http://www.stumbleupon.com/submit?url=http://www.testpage.com/testpage.aspx?test=34
What is the easiest way to programmatically add this customised hyperlink to a webpage?
Assuming that you have a hyperlink like that :
<asp:HyperLink runat="server" ID="myLink" Text="stumbleupon"></asp:HyperLink>
At server side :
string currentPagesUrl =
HttpUtility.UrlEncode(HttpContext.Current.Request.Url.AbsoluteUri);
myLink.NavigateUrl = string.Format("http://www.stumbleupon.com/submit?url={0}",
currentPagesUrl);
Or an alternative way (this one is easier I think) :
<a href="http://www.stumbleupon.com/submit?url=<%= HttpUtility.UrlEncode(HttpContext.Current.Request.Url.AbsoluteUri) %>" target="_blank">
stumbleupon 2</a>
I second Canavar's answer. You might want to also URL encode the currentPagesUrl string when building the hyperlink:
myLink.NavigateUrl = string.Format("http://www.stumbleupon.com/submit?url={0}",
Server.UrlEncode(currentPagesUrl));
Using jQuery:
$(document).ready(function(){
$("a.stumblethis").each(function(){
$(this).attr("href", "http://www.stumbleupon.com/submit?url="+$(this).attr("href"));
});
});
This will convert all links that have a class of "stumblethis".

Resources