Selenium with Java and Eclipse and SmartGWT - java

first time here and I tried to search for this info, so please forgive if this has been asked before. I am fairly knew to coding/selenium. I don't seem to have an issue with anything other than our SmartGWT screens and wondering if anybody could help with suggestions...I can't seem to get Selenium to work at all withing anything SmartGWT related actually
For example I have a date field and I want to type in a new date
This is the code according to firepath
<input id="isc_B" class="selectItemText" type="TEXT" tabindex="1131"
style="width:66px;height:12px;-moz-user-focus:normal;"
autocomplete="OFF" onselect="if (window.isc_ComboBoxItem_0 == null)
return;isc_ComboBoxItem_0.$54h()"
oninput="isc_ComboBoxItem_0._handleInput()" spellcheck="true"
$377="$378" $376="isc_ComboBoxItem_0" handlenativeevents="false"
name="valueField"/>
According to firepath these are the xpaths for it
[.//*[#id='isc_B']
html/body/div[4]/div[1]/div[2]/div/form/table/tbody[2]/tr[2]/td[1]/input
and I've tried these:
driver.findElement(By.xpath(".//*[#id='isc_B']")).sendKeys...;
driver.findElement(By.xpath("//*[#id='isc_B']")).sendKeys...;
driver.findElement(By.id("isc_B")).sendKeys...;
and can't get anything to recognize. any pointers would be awesome and thank you in advance. Do I need to import specific libraries for smartGWT or something?

Don't go by the XPaths suggested by FirePath..Try to create relative XPaths..Because absolute XPATHs can change..
For the above input tag I would recommend you use something like below
driver.findElement(By.className("selectItemText")).sendKeys("yourDate");
EDIT: Based on your website below is the code which works absolutely fine for me:
WebDriver driver=WebDriverFactory.getBrowser("http://www.tobymob.com/test/test.html");
driver.findElement(By.className("selectItemText")).sendKeys("someDate");

Related

Selenium Java clear method will not clear the input field?

I ran into a little issue today while validating some input fields in our application.
Looks like we can't call the selenium java method clear() to clear the input and I know I can iterate over the string and use sendKeys(Keys.Backspace) but clear method should do the work?
Anyone else ran into the same issue and how did you work around this problem.?
Our app is built upon Ant libraries
Selenium
String hotmarketNameEdit = "ant-input";
WebElement edit = driver.findElement(By.className(hotmarketNameEdit));
edit.click();
edit.clear();
HTML
<input type="text" id="label" class="ant-input ant-input-sm" value="AUTOMATION TEST - Thu Oct 21 09:54:15 MDT 2021" xpath="1">
Thanks for any inputs
I've personally come across this issue quite a few times, that Selenium .clear() method does not work properly.
Selenium community is aware of this issue, please see the bug reported here - ClearText does not work
You can go through the above-mentioned link.
Workaround :
Majority of time, I try to simulate Ctrl + A to select the text and just press delete after that.
If You are using Java as a binding language, You can do the following
webElement.sendKeys(Keys.CONTROL + "a")
webElement.sendKeys(Keys.DELETE)
have you tried JavaScriptExecutor?
JavascriptExecutor jse = (JavascriptExecutor) indexWebDriver;
jse.executeScript("arguments[0].value=''",edit);
check this one also
How can I consistently remove the default text from an input element with Selenium?
Can you please try this work around, passing both selecting and deleting keywords in one command
driver.findElement(By.name("username")).sendKeys(Keys.chord(Keys.CONTROL,"a", Keys.DELETE));

Selenium web driver can't find element

I have a problem when trying to find a Web Element using Selenium web driver.
I've done this with two pages, which both of the elements I'm wanting to grab are in lots of classes, ids, etc.
Here's the first one element, which I had no problems finding.
<input type="text" class="input-large" name="host" value="">
Which I used this to grab:
WebElement HtmlHost = driver.findElement(By.name("host"));
Now here's where my problem begins. I'm now trying to grab this:
<button type="submit" name="bootBtn" class="btn btn-inverse btn-large">Start hashing</button>
Which I've tried grabbing with all of these functions, but none have been able to find the element.
driver.findElement(By.partialLinkText("Start "));
driver.findElement(By.linkText("Start Hashing"));
driver.findElement(By.name("bootBtn"));
driver.findElement(By.cssSelector("button[type='submit']"));
What do you suggest I do?
Thanks.
driver.findElement(By.xpath("//button[contains(text(),'Start hashing')]"));
This will grab the element.
Okay I found the problem, and I feel pretty stupid that I missed this. The site I was trying to find the button requires you to login. I already knew this as I've coded the login process, but when I created this new void I placed it before the login process.
Sorry to waste time, thanks for help!
Try this
Thread.sleep(2000);
driver.findElement(By.xpath("//button[#type='submit']"));

[vaadin 6][Combobox] Dont show Suggestionbox when no Suggestion is in it

Im using Vaadin 6 in our Project and i wanted to use the Combobox as an element for textinput and selection. This is working fine, but i wondered if there is a possibility to not show the suggestion window, if there aren't any suggestion.
(wanted to upload a picture but wasn't allowed to)
I studied the code of the combobox and searched in the web so far for solution, but i could'nt get any infos about this topic.
So does someone has an idea how this might work out?
regards
If the container is empty add your own style to the Combobox:
comboBox.addStyleName( "empty-cb" );
Then add this to the CSS file:
.v-filterselect-suggestpopup-empty-cb {
display: none;
}

Selenium does not find element via xpath using Chromedriver

I'm using Chromedriver to try and find the following element:
<td class="section-menuoption"
onmouseover="this.className='section-menuoption-hilite';"
onmouseout="this.className='section-menuoption';" align="left"
onclick="self.jssDetails.location='products.php?xUser=kery&xRand=123';">
Scheduled Changes
</td>
When using the SeleniumIDE in Firefox I can use this selector without issue:
//*[contains(text(), 'Scheduled Changes')]
However, when I attempt to use this selector with the Chromedriver I get a "no such element" error (running via maven). My Chromedriver code looks likes this:
WebElement box = driver.findElement(By.xpath("//*[contains(text(), 'Scheduled Changes')]"));
System.out.print(box.getText());
box.click();
I've tried different quoting strategies, different xpaths (that also resolve correctly in the SeleniumIDE), but with no success. The only thing I can think of now is changing my XPath implementation, but I'm not even sure that's possible with Chromedriver.
Any help would be very appreciated.
First, make sure it it not in any kind of frames. Otherwise you need switch into the frame first, like this.
Then try use css selector instead of XPath. For example (you may need try different variations):
WebElement box = driver.findElement(By.cssSelector("td[onclick*=\"self.jssDetails.location='products.php?xUser=kery&xRand=123';\"]"));
Also, you might want to post every XPaths you have tried, to help us analyse.

Find xpath and get the value from anchor tag in selenium

I have been working on java project which needs the selenium testing tool for running the test class. As per the requirement, I need to know how to write the xpath, and how to get the value (goodluck) using xpath for given tag.
<span class="clienthome" id="personTableForm:foundClientsTable:0:j_id118">
goodluck</span>
Please anyone kindly help me.
try - //span[#class='clienthome']/.[normalize-space(text())='goodluck']
or
//span[normalize-space(text())='goodluck']

Categories