Executing Javascript on Selenium RC with PHP is a crucial skill to have in your toolkit

Is there a way to execute Javascript from Selenium RC? I have been trying different methods with no success so far.

I attempted the following approach:

I created a custom function in user-extensions.js:

function sayhello() {
    document.write('hello');
}

And then called it in WelcomeCept.php like this:

<?php

$I = new WebGuy($scenario);
$I->wait(3000);
selenium.getEval('sayhello');

Command used for execution:

php codecept.phar run acceptance WelcomeCept.php

Result obtained:

Codeception PHP Testing Framework v1.5.5 Powered by PHPUnit 3.7.14 by Sebastian
Bergmann.

Suite acceptance started PHP Fatal error:  Call to undefined function
getEval() in
/home/user/Projects/selenium/tests/acceptance/WelcomeCept.php on line
103



FATAL ERROR OCCURRED. TESTS NOT FINISHED. Call to undefined function
getEval()  in
/home/user/Projects/selenium/tests/acceptance/WelcomeCept.php:103

Answer №1

In my opinion, adding the sayhello within double quotation marks "" instead of single quotation marks '' should fulfill your intended outcome.

UPDATE Using either single or double quotes does not seem to be the problem. I am currently investigating the issue further.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What are some techniques for concealing error messages?

Can you assist in resolving this issue? There is a form which displays the inscription "You break my heart" immediately after loading, but I need it to only appear after the user attempts to enter text in the form. <div ng-app=""> <f ...

Tips for maintaining the integrity of blank space within a text node?

When intercepting a paste event and cleaning HTML off of the content using textNodes, I am faced with an issue where all white space is reduced to a single space and new lines are disregarded. For example, pasting: "hello world !" ends up being "h ...

Tips for resolving an issue with an array and the find method?

Seeking guidance on using the find method. Specifically, I am tasked with searching an array to find a specific string match. The catch is that this string may be nested within one of the objects in its child array. I attempted to create an if statement in ...

Several DIVs with the same class can have varying CSS values

I am looking to modify the left-margin value of various separate DIVs using JavaScript. The challenge is: I only want to use a single className, and I want the margin to increase by 100px for each instance of the class. This way, instead of all the DIVs ...

Removing a parameter from a variable in jQuery and JavaScript

I have coded something and assigned it to a variable. I now want to replace that value with another one. Just so you know, I do most of my coding in perl. Specifically, I am looking to remove the menu_mode value. Any advice on this would be greatly appre ...

Utilize Webpack to import a file containing exclusively global constants

I have a specific file filled with essential global constants that I am attempting to bring into another JavaScript file. This way, I can utilize these constants within the code of the second file. globalConstant.js global.RoutesOffersPage = { routes: ...

What is the benefit of using $q.all() with a single promise in AngularJS?

As I delve into this codebase, one snippet keeps popping up: $q.all([promise]).then(responseFunc); However, I find this confusing. After reading the documentation, I wonder why not simply use the following, as it's just a single promise... promise. ...

How to locate sub-elements using the @FindBy annotation of the parent element in Selenium/PageFactory?

I am in the process of transitioning my selenium tests to utilize the Page Object Model along with @FindBy. In my current object definitions, I have set up something similar to this: public WebElement objectParent() { return driver.findElement(By.name ...

Enhance your AngularJS skills by incorporating multiple conditions into the ternary operations of ng-class

I am struggling to apply multiple classes when the condition in the ng-class attribute evaluates to true. Here is the code I have attempted so far, but it doesn't seem to be working: <div class="col-md-4" ng-mouseover="hoverButton=true" id="plai ...

How can you notice when a DOM element is deleted from the page?

I am in the process of creating a custom directive that will ensure only one element is active at a time. Directive: displayOneAtATime Description: This directive can be applied to a DOM node to guarantee that only one element with this directive can be v ...

Update various components within a container

I have incorporated a function that automatically loads and refreshes content within a div every 10 seconds. Here is the script: $(function () { var timer, updateContent; function resetTimer() { if (timer) { window.clearTimeout(timer); ...

How can I interpret a string with a specific format using JavaScript?

Input String: var json_data = "{0:'apple', 1:'bannana', 2:'guava'}"; Desired Output after parsing with JavaScript: var json_data = { columns: [{0:'apple'}, {1:'bannana'} ,{2:'guava'}] ...

PhantomJS struggles to detect dropdown options that are dynamically loaded via AJAX

Recently, I've been attempting to scrape a website by utilizing a combination of PhantomJS and Selenium in Python. One problem that I encountered was with a dropdown on the page. This dropdown, when selected, triggers another dropdown to populate wit ...

Choose ng-change within the table

I've searched everywhere for an answer to this, but I couldn't find it. I have a table that contains select and date input fields. <table id="tblCorrAction" class="table table-bordered table-striped table-hover table-condensed"> <t ...

Ways to execute additional grunt tasks from a registered plugin

I am currently in the process of developing a custom Grunt plugin to streamline a frequently used build process. Normally, I find myself copying and pasting my GruntFile across different projects, but I believe creating a plugin would be more efficient. Th ...

What is the best way to extract values from a JavaScript function?

As someone who is new to Javascript, I am interested in learning how to retrieve values from a function. In the given code snippet, my goal is to extract TheName, TheHeight, TheGender, and TheSexuality when executing the function so that I can utilize the ...

Selenium in Python is failing to click after passing a text file in Xpath for a drop-down menu selection

I have a file with text that I want to use to select options from a dropdown list. However, my current code is not working as expected. f = open('address.txt',encoding="utf-8") lines = f.readlines() for line in lines: y =l ...

What is the best way to verify the presence of a value in an SQL column?

I need to check if a value exists in a column. If the value already exists, I do not want to insert it into the table. However, if it does not exist, then I want to add new data. Unfortunately, my attempted solution hasn't been successful. You can fi ...

Implementing pagination in Webgrid using AJAX post method

I've developed this JavaScript code: function PartialViewLoad() { $.ajaxSetup({ cache: false }); $.ajax({ url: "/ControllerAlpha/MethodBeta", type: "GET", dataType: "html", data: { s ...

Hide dropdown when clicked outside of it

Can someone help me modify my JavaScript code so that when I click on a new dropdown, it closes the previous one and keeps only the current one open? function manageDropdowns() { var dropdowns = document.querySelectorAll('.dropdown:not(.is-hove ...