c# selenium chrome-webdriver write advanced Path (chrome-driver) - c#

I just try to write correct path to click exactly this button what I want on my page. I will give you an example page for testing. You just have to download the HTML file and open it in your browser.Code of HTML page
What we now want to do?
If you run this HTML file you will see all page.
And now we want to make a Click on exactly this button on screen :
After when you click on this button you will see click counter below: like this :
Have anyone idea how to click it? I tried few ways and can't find solution still. Please help.
I try at least :
drive.FindElement(By.XPath("//tr[class='ng-scope']/td[text()='Wylaczenie nadan RDF'] and button[#title='Skip']")).Click();
and
drive.FindElement(By.XPath("//tr[text()='Wylaczenie nadan RDF']/button[#title='Skip']")).Click();
+ more and more and can't just write fine this Path to click exacly this button.
And unique value is <td class="ng-binding">Wylaczenie nadan RDF</td> - i prefer to get path by this.

You need to use below XPATH for the same
//tr[td='Wylaczenie nadan RDF']//button[#title='Skip']"
//tr[td='Wylaczenie nadan RDF'] will take you to the row which contains that text and then you use //button[#title='Skip'] to find that button

Related

How to open some pages by one HyperLink item?

I have an array of some URL links. And I need to open all theese links by clicking one HyperLink, located in cell of Telerik GridHyperLinkColumn.
Is there any method to do this?
Now I have a code which sets first way to my HyperLink:
HyperLink link = (HyperLink) item["documents"].Controls[0];
if (link.NavigateUrl.Contains(";"))
{
string[] linktext = link.NavigateUrl.Split(';');
link.NavigateUrl = linktext[0];
}
I would probably take a quick look at this SO answer here.
The takeaway is that this is not possible without using JavaScript functions:
Without JavaScript, it's not possible to open two pages by clicking
one link unless both pages are framed on the one page that opens from
clicking the link. With JS it's trivial.
The example is this:
<p><a href="#" onclick="window.open('http://google.com');
window.open('http://yahoo.com');">Click to open Google and Yahoo</a></p>
This would also work: (again see answer here)
Open Two Links With One Click

Press a button using class names in c# dom

So basically I want to press a button in a website and i dont know what code to use. The HTML line looks like this:
Click Here
I want the program to click on that Free Button using DOM. I tried this :
webBrowser1.Document.GetElementByClassName("free").InvokeMember("click");
But for some reason the GetElementByClassName is highlighted (in visual studio 2015)
I cannot change the HTML since the website is not mine.
It's highlighted cause there is no function GetElementByClassName in WebBrowser.Document!
Look at this, maybe it would help you:
How to select a class by GetElementByClass and click on it programmically

Search for a button by its HTML Code

I am writing Coded UI Test's for a web app. I am having problems such as I record actions using the test builder, however sometimes the button that is clicked has different information each time I run the test and as result VS can't find the button.
The html code never changes so what I want to do is find the button by its html code and click it that way.
For example on Google the path to the search button is
<button id="gbqfba" aria-label="Google Search" name="btnK" class="gbqfba"><span id="gbqfsa">Google Search</span></button>
How can I click this button using the code above or Alternativly using the XPath
//*[#id="gbqfba"]
Any help would be greatly appreciated.
adjust the Search Properties and Filter Properties.
Something like:
$('button span').each(function(){
If($(this).html() == "Google Search")
{
$(this).parent('button').click();
}
});
I found the answer, If you go to the UIMap.uitest file and click the method you have the problem with you can change the filter properties and the search properties to remove parts that are failing your test.
This will do the trick:
BrowserWindow.ExecuteScript("$('#gbqfba').click();");

Read content from a URL, place into a textbox

I'm trying to read lines from a website and then, copy it into my textBox2.
textBox1 will have a website's URL like http://example.com.
When I click on button1 I'd like to read HTML content from the above URL, and please that info textBox2.
Should I use HtmlAgilityPack?
How can this be done?
2 =================================================
So, for example, i copy this link into my "textBox1"
http://www.mineshaftersquared.com/server/DareCraft#
So, is there a way to make app copy everything from:
//*[#id="Plugins"]
to
//*[#id="rightInfo"]/section[2]/div/div[1]/table[2]
/this is XPath
/It don't have to in XPath, but this was the only way I could show.
You don't install HtmlAgilityPack, you reference if from your project.
Read about WebClient class (OpenRead method), you probably want to use it to get the pages.
Here is a tutorial you might want to start with:
http://www.codeproject.com/Articles/33798/HTTP-GET-with-NET-WebClient

<input> Cant fire the input event programmatically

Hi all - I need the user to select a file from a Dialog. I then only need the path to that file. I've been looking and the only way it seems is to use the <input> but i can't have the user click the choose file button, it must be "clicked" programmatically
Any help would be useful.
PS. THIS IS MY SECOND DAY OF ASP>NET - i also dont know javascript
Aiden
You can use jQuery to apply an event handler to the change event for the input type="file", but some browsers will return the file path name to the file, some will display a dummy path (with correct file name), and others will just give the file name with no path.
EDIT:
To click the file dialog programatically, you can hide it with css using display: none, and then do $("#<%=myFileInput.ClientID%>").click(); to prompt the dialog.

Categories