I have been trying this for a few days and am completely stuck. If anybody could help me out I would be very grateful; Im using VB.NET.
The HTML Code:
<tbody>
<tr>
<td class="chat-attachment-cell"></td>
<td class="chat-input-cell">
<textarea class="chat-message-input"></textarea>
</td>
<td class="chat-send-cell"><a href="#" class="chat-send-button"> alt="Send" width="66" height="66" border="0">
</a>
</td>
</tr>
</tbody>
The text box I need to input into is this bit
<textarea class="chat-message-input"></textarea>
Thankyou in advance for any help provided
You select the element then change the .innertext property with what you want.
There are multiple ways to do it, and I can't give you an example because I don't know what you are using nor the whole html, but for example it could look like this:
WebBrowser1.Document.GetElementById("someid").InnerText="Sometext"
For start, you can try looking how the collection of elements you get looks, then you should be able to figure out what to do next.
Dim test = WebBrowser1.Document.GetElementsByTagName("textarea")
For example on this page:
Dim test = WebBrowser1.Document.GetElementsByTagName("tbody")
test(1).InnerText = "Hi there"
Related
The DOM my test application changes depending upon the window size. So I am trying to write an XPATH which will cater for both of these scenarios.
Scenario 1: When the window is maximum size below is the dom:
<tbody>
<tr><td class="sv-table-col-xs"><img src="image.gif">
</td>
<td>03/Mar/2020</td>
<td><span class="sv-label sv-label-primary">You</span>
</td><td>0% of 1</td>
<td>Complete academic review</td>
</tr>
</tbody>
I am using xpath:
//tr[td[contains(text(), '03/Mar/2020')]]//a[text()='Complete academic review']
This works fine and finds the element.
Scenario 2: Below is the DOM when window is shrinked
<tbody>
<tr><td class="sv-table-col-xs">
<b class="tablesaw-cell-label">Status</b>
<span class="tablesaw-cell-content"><img src="../images/emailunr.jpg" style="border:0px" alt="..\images\icons\exploding_email1.gif.gif"></span>
</td>
<td><b class="tablesaw-cell-label">Due Date</b>
<span class="tablesaw-cell-content">03/Mar/2020</span>
</td>
<td><b class="tablesaw-cell-label">Primary Reviewer</b>
<span class="tablesaw-cell-content"><span class="sv-label sv-label-primary">You</span></span>
</td>
<td class="tablesaw-cell-hidden"><b class="tablesaw-cell-label">Other Reviewers</b>
<span class="tablesaw-cell-content">0% of 1</span>
</td>
<td class="tablesaw-cell-hidden"><b class="tablesaw-cell-label">Action</b><span class="tablesaw-cell-content">
Complete academic review
</span></td></tr>
</tbody>
For this the xpath changes to:
//tr/td[5]/span/a
to get to both elements I have tried to use:
//tr/td[5]/span/a | //tr[td[contains(text(), '03/Mar/2020')]]//a[text()='Complete academic review']
this xpath works but I on shrinked window I am not validating the element with text contains ''03/Mar/2020' & 'Complete academic review'.
Not sure if there is a way to validate the texts in both scenarios before selecting the element.
You want to use string value of a node. And function text() doesn't do it.
So instead use . or string() at least for date filtering part.
//tr[td[contains(., '03/Mar/2020')]]//a[text()='Complete academic review']
I'm facing the problem with finding label text from table
I'm new to Selenium, help me understand what I'm doing wrong.
Thanks in advance
WebElement services = driver.findElement(By.xpath("//tr[#id='mr_2']/label"));
String strServices = services.getText();
System.out.println(strServices);
<tr class="alt" id="mr_2">
<td class="first_col">Menu Selection</td>
<td><label style="display: none" for="element_2_1">Poor</label>
<input id="element_2_1" name="element_2" type="radio" value="1"></td>
</tr>
Try changing the below line
String strServices = services.getText();
to
String strServices = services.getAttribute("textContent");
I am using Java and firefox for automation.
i have the following table:
<table width="200" border="0">
<tbody>
<tr>
<td align="LEFT">User-ID: </td>
<td>
**<input name="username" size="25"/>**
</td>
</tr>
<tr>
<td align="LEFT">Password: </td>
<td>
**<input name="password" size="25" type="PASSWORD"/>**
</td>
</tr>
</tbody>
</table>
I need to reach the "Input name" and "Input password" in order to input my credentials. I have tried the following commands :
driver.findElement(By.xpath("html/body/div[7]/div[2]/form[2]/fieldset/table[1]/tbody/tr[1]/td[2]/input")).sendKeys("XXXXX");
driver.findElement(By.xpath("*//table//tbody//tr//td[2]/input/#name")).sendKeys("XXXXXXX");
In both cases eclipse found nothing.
Can some one assist me with the correct xPath?
The error massage in Eclipse is the following:
Exception in thread "main" org.openqa.selenium.InvalidArgumentException: Expected [object Undefined] undefined to be a string
Try this below code using xpath locator
driver.findElement(By.xpath("//input[#name='username']")).sendKeys("Username");
driver.findElement(By.xpath("//input[#name='password']")).sendKeys("XXXXXX");
Explanation of xpath:- Use name attribute of <input> tag.
Note:- Instead of using absolute xpath, use relative xpath.
OR
Try this below code using cssSelector
driver.findElement(By.cssSelector("input[name='username']")).sendKeys("Username");
driver.findElement(By.cssSelector("input[name='password']")).sendKeys("XXXXXX");
Looking at your HTML DOM this command will work for you:
You can use the "name" locator as:
driver.findElement(By.name("username")).sendKeys("your_username");
driver.findElement(By.name("password")).sendKeys("your_password");
OR
You can use the "xpath" locator as:
driver.findElement(By.xpath("//input[#name='username']")).sendKeys("your_username");
driver.findElement(By.xpath("//input[#name='password']")).sendKeys("your_password");
Let me know if it works for you.
I found out why your answers are not working.
The error that i am getting is an actual Firefox issue.
Please refer to this link:
https://bugzilla.mozilla.org/show_bug.cgi?id=1357661
Many thanks to all that tried to help me.
I want to find the the element for the Edit:
my java code is not working.
String xpathLocater = "//a[contains(text(),'onEditFilter('modifier')')]";
return driver.findElement(By.xpath(xpathLocater));
This is the source code for the element.
<tr class="listeven">
<td>
<a onclick="return onEditFilter('modifier');" href="#">Edit</a>
</td>
</tr>
something like
String xpathLocater = "//a[contains(#onclick,\"onEditFilter('modifier')\")]"
I need to getAttribute("src") of the image. When I run my script, it shows "null". BTW, action works!
My script:
WebElement image = driver.findElement(By.id("creativeLink"));
verifyDisplay(image.getAttribute("src"), By.id("creativeLink"));
action.moveToElement(image).perform();
Page HTML:
<div id="creativeContent">
<table>
<tbody><tr>
<td>
<a id="creativeLink" href="http://www.website.com" target="_new"> <img href="http://www.website.com" rel="faceboxMO" alt="" src="https://console.data.com/images/login/logo.png" height="50" border="0" width="50"></a>
</td>
<td valign="top"><div class="hint">(Note: Mouse over creative to see in correct dimensions)</div></td>
</tr>
<tr>
<td>
</td></tr></tbody></table>
</div>
Looks like you are using wrong selector there. Since you are using some custom function I was not able to test it. However, I came up with something like following and seems working. A correct selector should look like something as following:
// The selector finds the img element
By by = By.cssSelector("#creativeLink>img");
//Getting attribute on on img tag
String src = driver.findElement(by).getAttribute("src");
System.out.println(src);
Print
https://console.data.com/images/login/logo.png
Probably do something like this and it will work:
WebElement image = driver.findElement(By.cssSelector("#creativeLink>img"));
verifyDisplay(image.getAttribute("src"), By.cssSelector("#creativeLink>img"));
action.moveToElement(image).perform();