Selenium not able to find element by tag name "body" (only for IE) - selenium

HTML CODE
<html>
<head>
<body style="padding: 10px 25px; margin:0; left:0;right:0;top:0;bottom:0;position:absolute;font:14px 'robotoregular'; cursor:text; width: auto;">
<br _moz_editor_bogus_node="TRUE"/>
</body>
</html>
JAVA CODE
public TemplateOfNewLetter enterTextMessageToMessageField(String textMessage){
driver.switchTo().frame(0);
//driver.switchTo().frame(driver.findElement(By.tagName("iframe")));
//WebElement body = waitElementToBeClickable(By.cssSelector("html>body"));
WebElement body = waitElementToBeClickable(By.tagName("body"));
body.click();
body.sendKeys(textMessage);
driver.switchTo().defaultContent();
return this;
}
I tried to use the code above but the issue is still reproduced in explorer (for FF and Chrome tests passed)
Please advice how can I enter text to the text message field

you didn't have frame to switch to.
you can't send text to body.
Try to look how to use selenium in this link:
http://seleniumeasy.com/selenium-webdriver-tutorials

Related

docx4j html to pdf word-break issue

<html>
<head>
<style>
p {
word-break: break-all;
}
</style>
</head>
<body style="width: 500px">
<p>
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>
</body>
</html>
the html code is looks this ↑
This is the effect of html in the browser [Click to view]
#Test
void contextLoads() throws Docx4JException, FileNotFoundException, MalformedURLException {
File file = new File("C:\\Users\\zx\\Desktop\\data2.html");
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(wordMLPackage);
wordMLPackage.getMainDocumentPart().getContent().addAll(XHTMLImporter.convert(file.toURI().toURL()));
Docx4J.toPDF(wordMLPackage, new FileOutputStream("C:\\Users\\zx\\Desktop\\3.pdf"));
}
the java code is looks this ↑
This is the effect of pdf in the browser [Click to view]
I want him to install the CSS style as shown in the following figure, and return the line
The html importer that comes with docx4j can't handle a separated css file.
The styles should be inline in the html tags for being considered, in a style property.
And for inserting a break line, and move to the next line, in pdf it should be another text box, therefor you have to create a paragraph for each line you want, by measuring how many characters you can place in a single line.

Selenium - Unable to send text on the webpage which has hidden element

This is the webelement which is hidden in a page
<form method="post" action="" data-reactid="x.x.x.x">
<input class="barcode-input" data-reactid="x.x.x.x" type="text">
</form>
It doesn't have a hidden tag instead it is positioned # top: -9999px;
When i try this
driver.findElement(By.xpath("//input[#class='barcode-input'][#type='text']")).sendKeys("barcode123"+Keys.RETURN);
I get this
cause: org.openqa.selenium.ElementNotVisibleException, message: 'Element is not currently visible and so may not be interacted withCommand duration or timeout: 10.04
When tried to print the isDisplayed and isEnabled property for this element i get
isDisplayed = false,
isEnabled = true
The CSS style
input.barcode-input[type="text"] {
border-radius: 0 !important;
box-shadow: none !important;
outline: 0 none !important;
position: fixed;
top: -9999px;
transition: none 0s ease 0s !important;
}
If i disable the top css property which is shown above, i am able to see the text box. This is a webpage which is expecting user to scan a barcode and append "ENTER" keys to it.
Appending Enter keys i can use KEYS.RETURN.
But issue is with the actual text which needs to be passed to this element.
Actual page doesn't have a text box displayed on screen though since it expects user to scan barcode.
Is there a way to bring the element to focus and send keys to it?
First of all you have to change the value of type attribute as text from hidden. The following code using javascript would work for that:
jse.executeScript("document.getElementsByName('body')[0].setAttribute('type', 'text');");
Now, you are able to type on that text by using WebDriver. So, the overall code for typing with WebDriver using Java and Javascript as follows:
WebDriver driver = new FirefoxDriver();
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("document.getElementsByName('body')[0].setAttribute('type', 'text');");
driver.findElement(By.xpath("//input[#name='body']")).clear();
driver.findElement(By.xpath("//input[#name='body']")).sendKeys("Ripon: body text");
Tried this and it resolved the issue
JavascriptExecutor javascript = (JavascriptExecutor) driver;
javascript.executeScript("document.getElementsByClassName(\"barcode-input\")[0].style.top=\"1\";");
javascript.executeScript("document.getElementsByClassName(\"barcode-input\")[0].value=\"test123\";");
driver.findElement(By.xpath("//input[#class='barcode-input']")).sendKeys(Keys.RETURN);

C# Selenium Webdriver (Firefox) iFrame does not allow text to be entered via sendKeys

I'm using latest Selenium Firefox (2.53.0)
Previously code was working when performing the following
1) Finding the iFrame by Xpath iframe class
IWebElement detailFrame = `Driver_Lib.Instance.FindElement(By.XPath("//iframe[#class='cke_wysiwyg_frame cke_reset']"));`
2) Switching to that frame by
Driver_Lib.Instance.SwitchTo().Frame(detailFrame);
3) finding the p tag within the iFrame by
IWebElement freeText = Driver_Lib.Instance.FindElement(By.TagName("p"));
4) Inserting a simple string to the iframe text box
freeText.SendKeys("this is some text");
5) switching from the iFrame back to the main contentwindow by
Driver_Lib.Instance.SwitchTo().DefaultContent();
Here is the code part from the application
<iframe class="cke_wysiwyg_frame cke_reset" frameborder="0" src="" style="width: 100%; height: 100%;" title="Rich Text Editor, ctl00_ctl00_MainContentPlaceHolder_PageContent_mlcEditor_CKEditor" aria-describedby="cke_61" tabindex="0" allowtransparency="true">
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<title data-cke-title="Rich Text Editor, ctl00_ctl00_MainContentPlaceHolder_PageContent_mlcEditor_CKEditor">Rich Text Editor, ctl00_ctl00_MainContentPlaceHolder_PageContent_mlcEditor_CKEditor</title>
<style data-cke-temp="1">
<link href="https://myUrl/contents.css" rel="stylesheet" type="text/css">
<style data-cke-temp="1">
</head>
<body class="cke_editable cke_editable_themed cke_contents_ltr cke_show_borders" contenteditable="true" spellcheck="false">
<p>
<br _moz_editor_bogus_node="TRUE">
</p>
</body>
</html>
</iframe>
The test I am running is a simple one, open up that page, insert some text, save.
It not inserting the text into the iFrame. I am totally puzzled as to why.
Has anyone else found this issue at all?
Many thanks
I have removed the exception, this was a redHerring.
the iFrame can not have text entered into it
hi all I've found the solution:~ here is the summary of what was happening:
1) The iFrame was being located by xPath.
2) the SwitchTo() method used placed focus in the detailFrame instance of IWebElement
3) What was not happening was the p tag could not be located as it was contained withing a CSS Body Class that.
The solution was staring me in the face the whole time! so simple!!
I did this:
IWebElement detailFrame = Driver_Lib.Instance.FindElement(By.XPath("//iframe[#class='cke_wysiwyg_frame cke_reset']"));
Driver_Lib.Instance.SwitchTo().Frame(detailFrame);
IWebElement freeText = Driver_Lib.Instance.FindElement(By.TagName("body"));
freeText.SendKeys("This is a free text question created by Automation Smoke Test");
Driver_Lib.Instance.SwitchTo().DefaultContent();
So as you see, simply locating the 1st instance of the body tag!

WebDriver unable to locate element /p

I am trying to locate element p, which is a blank text area to fill, however webdriver throws exception that element is not found. I have tried:
css = "#tinymce>p"
xpath = "//*[#id='tinymce']/p"
on the following page
<head xmlns="http://www.w3.org/1999/xhtml">
<body id="tinymce" class="mceContentBody aui-theme-default wiki-content fullsize page-edit" contenteditable="true"onload="window.parent.tinyMCE.get('wysiwygTextarea').onLoad.dispatch();" dir="ltr" style="padding-top: 100px;">
<p>
<br/>
</p>
You have xmlns="http://www.w3.org/1999/xhtml", which means you will have to ask p with the namespace included.
xpath = "//*[#id='tinymce']/*[local-name() = 'p']"
Should work.
i use nth-child function with cssselector.
#tinymce p:nth-child(1)
Check out the fiddle

Selenium WD - southwest.com

I am constantly getting "No Such Element Exception" for "First Name" test box
Below is my code:
public class southwestSignUpSave {
WebDriver oBrw;
#Before
public void loadwebsite (){
oBrw = new FirefoxDriver();
oBrw.manage().window().maximize();
oBrw.get("https://southwest.com");
oBrw.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void signUpAndSave(){
oBrw.findElement(By.partialLinkText("OFFERS")).click();
oBrw.findElement(By.partialLinkText("Sign")).click();
//oBrw.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebDriverWait oWait = new WebDriverWait(oBrw, 30);
oWait.until(ExpectedConditions.presenceOfElementLocated(By.id("FIRST_NAME")));
oBrw.findElement(By.id("FIRST_NAME")).clear();
oBrw.findElement(By.id("FIRST_NAME")).sendKeys("abc");
oBrw.findElement(By.id("LAST_NAME")).clear();
oBrw.findElement(By.id("LAST_NAME")).sendKeys("asd");
oBrw.findElement(By.id("EMAIL")).clear();
oBrw.findElement(By.id("EMAIL")).sendKeys("abc#asd.com");
new Select(oBrw.findElement(By.id("HOME_AIRPORT"))).selectByVisibleText("Akron/Canton, OH - CAK");
oBrw.findElement(By.id("IAN")).click();
}
}
I tried to use id and name.
where am I going wrong. I am new to Selenium WD
U can try finding the element using xpath. For that u need to install the firepath plugin in firefox and then inspect the element using firepath.
oBrw.findElement(By.xpath("copy paste the xpath here")).clear();
I would also recommend loading the driver using System property inside loadwebsite() method.
System.setProperty("webdriver.firefox.driver", "//your driver path");
oBrw=new FirefoxDriver();
if the Sign page opens in a new tab/window then u need to navigate to that tab/window because Selenium by default stays in the opening tab. To navigate u need to add the following lines of code after clicking on "Sign"-
Set<String> s=wd.getWindowHandles();
Iterator<String> it=s.iterator();
it.next();//control goes to 1st default tab
String str=it.next().toString();//control goes to the next tab
oBrw.switchTo().window(str);//driver switches to the new window/tab.
if the element is present inside a frame then also u need to switch to that frame first before finding element inside it. Below is the code-
WebElement web=oBrw.findElement(By.xpath("copy paste your frame xpath"));
oBrw.switchTo.frame(web);
now try to find the element present in the new tab/window.
FIRST NAME input text field is inside iframe. Check the below piece of HTML.
<iframe frameborder="0" src="https://luv.southwest.com/servlet/formlink/f?kOHpjQACAY" onload="scroll(0,0);" verticalscrolling="no" horizontalscrolling="no" scrolling="no" title="Click 'n Save signup form"></iframe>
<html dir="ltr">
<head>
<body>
<p>
<span class="required">*Required</span>
</p>
<div class="clear"></div>
<form id="cnsForm" onsubmit="return validateForm();" action="https://luv.southwest.com/servlet/campaignrespondent" method="POST">
<div class="form_field first_name">
<label for="first_name">
<input id="FIRST_NAME" type="text"=""="" maxlength="25" size="22" name="FIRST_NAME">
</div>
...
Hence selenium is unable to find out the element. Here we need to explicitly switch to iframe as below. Insert below code snippet before you find FIRST_NAME. (You can insert well formatted xpath of iframe. I just grabbed it from firebug.)
WebElement iframeSwitch = oBrw.findElement(By.xpath("/html/body/div[1]/div[3]/div[2]/div[1]/div/div/div[4]/div/div/div/div[3]/iframe"));
oBrw.switchTo().frame(iframeSwitch);
That Text box is inside an iFrame, so you need to switch to that iFrame first then try findElement method to locate textbox.
oBrw.findElement(By.partialLinkText("OFFERS")).click();
oBrw.findElement(By.partialLinkText("Sign")).click();
oBrw.switchTo().defaultContent();
oBrw.switchTo().frame(0);
WebElement id = oBrw.findElement(By.name("FIRST_NAME"));
id.sendKeys("USERNAME");
Hope this helps.