Selenium IE Page title is not working. Tried IWebDriver.Title - selenium

I asked this question last week and someone marked it as a duplicate. However the duplicate reference did not answer or give solution to my question.
I am trying to get the page title to a complicated html page. I am trying to get the 'By' locator used to find an element. This is the HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="ctl00_Head1"><title>
Smart Tracking System
</title><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" /><link rel="shortcut icon" type="image/x-icon" href="../images/desktopicon.ico" /><link href="../App_Themes/appthemes/appstyles.css" type="text/css" rel="stylesheet" /><link href="../App_Themes/appthemes/calendarstyles.css" type="text/css" rel="stylesheet" /><link href="../App_Themes/appthemes/tabsstyles.css" type="text/css" rel="stylesheet" /></head>
<body>
When I copy the xpath from Firefox source code, it says the xpath is:
/html/head/title
I am using C# code to do the validation but I keep getting "LoadableComponentException..."
This is my C# code:
public class AccountsOverviewPage : CVALoadableComponent<AccountsOverviewPage>
{
private IWebDriver _driver;
private By textlabelPageHeader = By.XPath("//head[#class='title' and text()='Smart Tracking System']");
public AccountsOverviewPage()
{
_driver = ScenarioContext.Current.Get<IWebDriver>();
}
protected override void ExecuteLoad()
{
}
protected override bool EvaluateLoadedStatus()
{
if (!CVAElements.WaitForElementOnPageLoad(_driver, textlabelPageHeader))
{
UnableToLoadMessage = "Could not load Accounts Overview page within the designated timeout period";
return false;
}
return true;
}
public bool IsAt()
{
return CVAElements.CheckElementIsVisible(_driver, textlabelPageHeader);
}
}
I have even tried doing the validation by Id, and this time I used an element Id that I am sure is there:
private By textlabelPageHeader = By.Id("ctl00_Head1");
and still the validation failed. What am I not doing?? Please any assistance will be greatly appreciated.
UPDATE
This is how I am using the Driver.Title method:
public class AccountsOverviewPage : CVALoadableComponent<AccountsOverviewPage>
{
private IWebDriver _driver;
// error happens on this line:
string textlabelPageHeader = _driver.Title;
public string TextlabelPageHeader
{
get
{
return textlabelPageHeader;
}
set
{
textlabelPageHeader = value;
}
}
public AccountsOverviewPage()
{
_driver = ScenarioContext.Current.Get<IWebDriver>();
}
protected override void ExecuteLoad()
{
}
protected override bool EvaluateLoadedStatus()
{
if (!CVAElements.WaitForElementOnPageLoad(_driver, TextlabelPageHeader))
{
UnableToLoadMessage = "Could not load Accounts Overview page within the designated timeout period";
return false;
}
return true;
}
public bool IsAt()
{
return CVAElements.CheckElementIsVisible(_driver, TextlabelPageHeader);
}
and I getting error: "A field initializer cannot reference the non-static field, method, or property" here
string textlabelPageHeader = _driver.Title;

What you're trying to access - a page title - is not a web element. It's a property of the web page itself. In Selenium, you access the page title by:
String pageTitle = _driver.getTitle();
I program in Java, so that might not be the correct syntax for C#

Related

Switch to at Iframe in selenium java

I am new using selenium and I am trying to test a web page. This page has as iframe and for the read I need do a switch, the switch I did was:
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(frame));
But it does not works, maybe somebody should be help me? Here is my code. this code of my page:
public class MainPage extends BasePageObject{
#FindBy(id = "cc-sa-item-logo")
WebElement iconLogin;
private By frame = By.xpath("//iframe[#id='cms']");
public MainPage() {
PageFactory.initElements(driver, this);
waitUntilPageObjectIsLoaded();
}
#Override
public void waitUntilPageObjectIsLoaded() {
wait.until(ExpectedConditions.visibilityOf(iconLogin));
}
public boolean logOutExists() {
boolean res = true;
String parentWindow = driver.getWindowHandle();
try{ wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(frame));
res = iconLogin.isDisplayed();
}finally {
driver.switchTo().window(parentWindow);
}
return res;
}
and this is the code of page the test:
<iframe id="cms" class="cms" src="/app/s9cea6fcedc36dd82/p430c9b54081c966d/" onload="this.loaded = true;" name="cms">
<!DOCTYPE html>
<html lang="es-ES">
<head>
<body id="page-2281940529" class="body cc-page cc-page-index cc-indexpage j-m-flash-styles j-m-gallery-styles j-m-video-styles j-m-hr-styles j-m-header-styles j-m-text-styles j-m-emotionheader-styles j-m-htmlCode-styles j-m-rss-styles j-m-form-styles-disabled j-m-table-styles j-m-textWithImage-styles j-m-downloadDocument-styles j-m-imageSubtitle-styles j-m-flickr-styles j-m-googlemaps-styles j-m-blogSelection-styles-disabled j-m-comment-styles j-m-jimdo-styles j-m-profile-styles j-m-guestbook-styles j-m-promotion-styles j-m-twitter-styles j-m-hgrid-styles j-m-shoppingcart-styles j-m-catalog-styles j-m-product-styles-disabled j-m-facebook-styles j-m-sharebuttons-styles j-m-externalSource-styles j-m-formnew-styles-disabled j-m-callToAction-styles j-m-turbo-styles j-m-spacing-styles j-m-googleplus-styles j-m-dummy-styles j-footer-styles cc-content-parent" style="background-position: -186px 0px;">
<div class="cc-bs cc-alert-container" ng-controller="cms.common.AlertCtrl"> </div>
<div id="cc-eh" data-display="cms-only">
<div id="cc-nav" class="cc-jimdo ui-draggable" data-display="cms-only">
<script>
<div id="cc-clipboard" class="cc-clipboard-scrolled-left cc-clipboard-scrolled-right cc-clipboard-empty" data-display="cms-only" style="right: 186px; display: block;">
<div id="cc-inner" class="cc-content-parent" style="padding-right: 186px; padding-top: 0px;">
<div id="cc-sa" data-display="cms-only" style="display: block;">
<div id="cc-sa-sidebar" ng-controller="cms.sa.SidebarCtrl">
<div class="cc-sa-sidebar-group cc-sa-sidebar-group--top">
<div class="cc-sa-sidebar-logo-open clear">
<span id="cc-sa-item-logo" class="cc-sa-sidebar-logo" data-params="/app/siteadmin/upgrade/index/,true" data-action="sidebarItem"> </span>
I need find the element of span tag
The issue here is that the first thing you do, after initializing the FindBy-annotated fields, is waitUntilPageObjectIsLoaded, which is implicitly calling driver.findElement(By.id("cc-sa-item-logo")).
And here it fails, as you haven't switched to the frame yet at this point, and unfortunately PageFactory is not able to handle that.
Basically you need to wrap each and every call to a FindBy-annotated field with a switchTo().frame/switchTo().defaultContent(). Just like you did in logOutExists.
For convenience, I would model the iframe in a separate page object (class), so as to encapsulate (and automate) the switching back and forth.
public class CmsIframe extends BasePageObject implements AutoCloseable {
#FindBy(id = "cc-sa-item-logo")
WebElement iconLogin;
private By frame = By.xpath("//iframe[#id='cms']");
public CmsIframe() {
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(frame));
PageFactory.initElements(driver, this);
waitUntilPageObjectIsLoaded();
}
#Override
public void waitUntilPageObjectIsLoaded() {
wait.until(ExpectedConditions.visibilityOf(iconLogin));
}
public boolean logOutExists() {
return iconLogin.isDisplayed();
}
#Override
public void close() {
driver.switchTo().defaultContent();
}
}
MainPage can then be re-written as follows:
public class MainPage extends BasePageObject{
private By frame = By.xpath("//iframe[#id='cms']");
public MainPage() {
PageFactory.initElements(driver, this);
}
public boolean logOutExists() {
try (CmsIframe cmsIframe = new CmsIframe()) {
return cmsIframe.logOutExists();
} // when exiting this try block, the driver will automatically be switched back out of the iframe (as part of CmsIframe#close)
}
}
Please note that thanks to implements AutoCloseable, CmsIframe can be used in a try-with-resources Statement (java > 7 only), which sorts of automates the switching back to the default content.
PS: if you could post the stacktrace with the exception you are getting, that would help help you.
I finally solved my problem, you had reason the problem was that I find the switch in the place incorrect. the solution was:
#Override
public void waitUntilPageObjectIsLoaded() {
String parentWindow = driver.getWindowHandle();
try{
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(frame));
wait.until(ExpectedConditions.visibilityOf(iconLogin));
}finally {
driver.switchTo().window(parentWindow);
}
}
public boolean logOutExists() {
boolean res = true;
String parentWindow = driver.getWindowHandle();
try{
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(frame));
res = iconLogin.isDisplayed();
}finally {
driver.switchTo().window(parentWindow);
}
return res;
}

Prestsahop Meta title

I have create a custom module to display some images and text.I want to have a header for this module because I don't want to have the title frmo website.I need a individual title so I think I need to have a different header for this module or how can I have a title just for this module? The code for meta title is:
meta charset="utf-8" />
<title>{$meta_title|escape:'html':'UTF-8'}</title>
{if isset($meta_description) AND $meta_description}
<meta name="description" content="{$meta_description|escape:'html':'UTF-8'}" />
{/if}
So I will need the title to be My title
Can someone help me?
Page that you have created with your module are presumably FrontControllers. Otherwise, existing pages already have their purpose and meta tags.
If you did use FrontController to create a Page, then you can input meta information for your page in SEO & URLs > SEO & URLs > Add. There you can input custom url-rewrite for your page and met info.
#gskema This is my php code for module :
if (!defined('_PS_VERSION_'))
exit;
class mymodule5 extends Module
{
/* #var boolean error */
protected $_errors = false;
public function __construct()
{
$this->name = 'mymodule5';
$this->tab = 'front_office_features';
$this->version = '1.0';
$this->author = 'author';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('mymodule5');
$this->description = $this->l('Pagina livrare');
$this->confirmUninstall = $this->l('Are you sure you want to delete this module?');
}
public function install()
{
if (!parent::install())
return false;
return true;
}
public function uninstall()
{
if (!parent::uninstall())
return false;
return true;
}
public function countAllProducts()
{
return Db::getInstance()->getValue('SELECT COUNT(*) from ps_product WHERE active = 1');
}
public function setMedia()
{
parent::setMedia();
$this->addCSS(__PS_BASE_URI__.'modules/'.$this->module->name.'/css/'.$this- >module->name.'.css');
}
}

jsf variable lost value [duplicate]

This question already has an answer here:
#ViewScoped calls #PostConstruct on every postback request
(1 answer)
Closed 5 years ago.
I have a managed Bean called bean1.java that has a boolean var called found. The variable says if a client has been found or not.
The bean has a method validate() that goes to the DB and checks if the client exists, and sets the variable to found=true if it exists or 'false' if it doesn't.
Then I keep completing other fields in my form. Now, when I click the button save, it the method saving(). That method has to do an action if the var found is true and another action if it's false.
But the problem is when I validate the variable that has been set to true on the method validate(), now it has the value "false".
#ManagedBean
#ViewScoped //SessionScoped
public class AgregarPoliza implements Serializable{
public boolean found=false;
public void validate(){
// go to data base and validate if the client exist, when exist
// set variable true
found = true; // setFound(true); <--- i already try this way too
}
public void saving(){
//it has two actions to do but need to know the value of found
System.out.println("my var found has" + found); //this system.out shows false
if(found ==true){
//makes an action
}
else{
//makes another action
}
}
//get and set of the value found
}
You should try calling the validate method in the method saving like this.
public void validate()
{
// go to data base and validate if the client exist, when exist
// set variable true
found = true; // setFound(true); <--- i already try this way too
}
public void saving(){
this.validate();
//it has two actions to do but need to know the value of found
System.out.println("my var found has" + found); //this system.out shows false
if(found ==true){
//makes an action
}
else{
//makes another action
}
i hava use this and this is working fine now check it please now it can not lost value...
AgregarPoliza.java
package com.best.uibeansTest;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
#ManagedBean(name = "agregarPoliza")
#SessionScoped
public class AgregarPoliza implements Serializable{
public boolean found=false;
public void validate(){
// go to data base and validate if the client exist, when exist
// set variable true
found = true; // setFound(true); <--- i already try this way too
}
public String saving(){
validate();
//it has two actions to do but need to know the value of found
System.out.println("my var found has" + found); //this system.out shows false
if(found ==true){
//makes an action
}
else{
//makes another action
}
return "test2.xhtml" ;
}
//get and set of the value found
public boolean isFound() {
return found;
}
public void setFound(boolean found) {
this.found = found;
}
//get and set of the value found
}
here i just get agregarPoliza as bean i am showing jsf code below through which i check this..
test2.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
<title>JSF Tutorial!</title>
</head>
<h:body>
<h2>Result</h2>
<hr />
<h:form>
<p:commandButton value="Save" ajax="false" action="#{agregarPoliza.saving}"/>
|
found value:
#{agregarPoliza.found}
</h:form>
</h:body>
</html>
on clicking of save button found value is changed to true. try this..

Filter Column Doesn't Display

I'm trying to set up a basic Mvc.Jquery.Datatables runthrough. I'm getting an extra row at the top which isn't the expected filter row.
There is a script error in the background 'Uncaught TypeError: {object Object} has no method 'columnFilter' as shown below
My Index View is
#using DataTables.Controllers
#using Mvc.JQuery.Datatables
#using Mvc.JQuery.Datatables.Serialization
<script src="~/Content/DataTables/media/js/jquery.js"></script>
<script src="~/Content/DataTables/media/js/jquery.dataTables.js"></script>
<link href="~/Content/DataTables/media/css/demo_table.css" rel="stylesheet" />
<h2>Datatables Demo</h2>
#{
var vm = Html.DataTableVm("table", (HomeController h) => h.GetDataObject(null), null);
vm.ColumnFilter = true;
vm.StateSave = true;
}
#Html.Partial("DataTable", vm)
My controller code is
public class HomeController : Controller
{
public ActionResult Index()
{
var data = DataRepository.GetData();
return View(data);
}
public DataTablesResult<MyDataObject> GetDataObject(DataTablesParam dataTablesParam)
{
var data = DataRepository.GetData().Select(o => o).AsQueryable();
return DataTablesResult.Create(data, dataTablesParam);
}
}
How to get the sort row to show? Thanks.
** Solution **
As suggested, I was missing the script
<script src="~/Content/jquery.dataTables.columnFilter.js"></script>
I think you have a missing script tag for the column filter extension. compare the references against the example page.
also make sure you are using EmbeddedResourceVirtualPathProvider or have the templates project installed

MVC4 custom unobtrusive validator isn't working

not sure what is wrong. Syntax seems correct.... but it still doesn't fire on client side. If I submit the form, I get server side validation, client side nothing...
Here is the code that is on the page:
<script src="#Url.Content("~/Scripts/jquery.validate.min.js")"></script>
<script src="#Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"></script>
<script type="text/javascript">
// we add a custom jquery validation method
(function ($) {
$.validator.addMethod('additive', function (value, element, params) {
//just return false to test it.
return false;
});
// and an unobtrusive adapter
$.validator.unobtrusive.adapters.add("additive", ["field2", "field3", "field4"], function (options) {
var params = {
field2: options.params.field2,
field3: options.params.field3,
field4: options.params.field4
};
options.rules['additive'] = params;
if (options.message) {
options.messages['additive'] = options.message;
}
});
}) (jQuery);
</script>
Here is the part that is on the validator that is related to client side (IClientValidatable):
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
ModelClientValidationRule rule = new ModelClientValidationRule
{
ValidationType = "additive",
ErrorMessage = "ERROR MESSAGE"
};
rule.ValidationParameters.Add("field2", propName2);
rule.ValidationParameters.Add("field3", propName3);
rule.ValidationParameters.Add("field4", propName4);
yield return rule;
}
The model is decorated as following:
[SumValidation("OtherField2...")]
public int MyField { get; set; }
When field renders, it is all there, all the stuff from the server side in terms of data-xxx attributes. Just this specific client validation does not fire. Anyone see what I'm missing?
figured it out. If anyone runs into this. Added custom validation too late on the page. After I moved my custom validation javascript to the head section of the _Layout.cshtml it started to work.
So if your script looks right, good place to check.
Another work around is to run $.validator.unobtrusive.parse('form'); which reloads all the validators.