webdriverIO 5, how to switch to iframe when its element 'id' not given? - selenium-webdriver

frame html code:
<iframe title="frame report" class="ReportViewer__iframe" src="/yesyyy.aspx?reportId=145&ts=1550681978158&bgcolor=#f8f9fb" width="100%" height="100%"></iframe>
script fails both for title and class name locators -- 'ERROR webdriver: Request failed due to Error: no such frame'

Use the following code.
driver.switchTo().defaultContent();
WebElement frameXpath = driver.findElement(By.xpath("//iframe[#title='frame report']"));
driver.switchTo().frame(frameXpath);

Got the solution, pass the object of the iframe with available locators (title or css class)
browser.switchtoframe($('.report__iframe'))

HTML Code:
iframe id="ifr" name="demo" src="demo.html" height="200" width="300">
Switch statement:
browser.switchToFrame($("//iframe[#src='demo.html']"))
For more info read here: https://chercher.tech/webdriverio/iframes

Related

Cannot get a valid selector to implement I.click()

I am trying to click a button that has these details when I F12
<a data-codecept="searchGo" id="9" class="a-button a-button--white clearfix block showall" suggestrow"="" alt="/s/lundhags/?searchparam=lundhags" onmouseover="suggest.handleMouseOver(9);" onmouseout="suggest.handleMouseOut(9)" onclick="suggest.handleSubmit();" xpath="1">Show all results for 'lundhags'<span class="a-icon a-button__icon a-button__icon--double-arrow"></span></a>
I have copied xpath and I had a code like this=>
I.click('//*[#id="9"]');
and I got this error
Clickable //*[#id="9"] was not found by text|CSS|XPath
What am I doing wrong?
It works now! I used the specific Identifier
I.click('[data-codecept="searchGo"]');

Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Cannot read property 'defaultView' of undefined [duplicate]

I am trying to use Selenium for Python eith the Chrome webdriver to automate the download of a file.
My program works perfectly up to the last step (clicking on the 'download' button) at which point a dialog box is triggered with the text:
"An error has occured in 'site url': Uncaught TypeError: Cannot read property 'getColomnSet' of undefined41"
What does this error mean and what are the most probable causes?
For reference, here are the last few commands of my program:
try:
elem = wait.until(EC.presence_of_element_located((By.ID,'element_1_id')))
finally:
elem1 = driver.find_element_by_id('element_1_id')
elem2 = driver.find_element_by_id('element_2_id')
action = ActionChains(driver).move_to_element(elem1).move_to_element(elem2)
action.perform()
elem2.click()
This error message...
An error has occured in 'site url': Uncaught TypeError: Cannot read property 'getColomnSet' of undefined
...implies that your program was unable to read the property getColomnSet while trying to download the desired file.
Possibly, the main problem is the js involved to download the document is invoked before the client renders the HTML DOM completely.
The relevant HTML, a bit more of your previous lines of code and the error stack trace would have given us some more idea about what's going wrong.
Solution
You can induce some measures to wait till the complete DOM Tree is rendered following the discussion:
Generic funtion to check if page has completely loaded in Selenium
A couple of facts:
In your code trials I don't see you interacting with the element (By.ID,'element_1_id') so possibly you can remove the step of presence_of_element_located() for the element (By.ID,'element_1_id').
If you still require presence_of_element_located((By.ID,'element_1_id')) catch the exception and initiate required steps.
As you invoke move_to_element() over elem1 and elem2 and moving ahead invoke perform() you need to induce WebDriverWait with expected_conditions as element_to_be_clickable(locator)
tl;dr (references)
Cannot read property 'getContext' of null, using canvas
Uncaught TypeError: Cannot read property 'getContext' of undefined
Uncaught Error remote.js
Try the following - it works on Salesforce Lightning UI screens:
WebElement element = driver.findElement(By.id("your ID"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);

How can I click this using selenium webdriver?

I have an element like this:
<a class="btn">Select</a>
How do I click this using selenium webdriver?
To click() on the link with text as Select you can use either of the following options :
Python link_text :
driver.find_element_by_link_text("Select").click()
Python xpath :
driver.find_element_by_xpath("//a[#class='btn' and contains(.,'Select')]").click()
Java linkText :
driver.findElement(By.linkText("Select")).click();
Java xpath :
driver.findElement(By.xpath("//a[#class='btn' and contains(.,'Select')]")).click();

angularJS ng-src with trustAsResourceURL

I am trying to create an iframe in my webpage with ng-src="localhost/test/public/getreportsdata/1". I used the trust source function $sce.trustAsResouceUrl and that's to open the result of the service in the iframe.
I tested it on my laptop it worked, now on my desktop it giving me :
cannot read property 'trustAsResourceUrl' of undefined
My html iframe :
<iframe width="800" height="800" ng-src="{{trustSrc(reportbydateresource.src)}}"></iframe>
My js code :
angular.module('backOfficeApp')
.controller('CheckReportsCtrl', CheckReportsCtrl);
CheckReportsCtrl.$inject=['$scope','$http','$filter'] ;
function CheckReportsCtrl($scope,$http,$filter,$sce){
$scope.trustSrc = function (src){
return $sce.trustAsResourceUrl9src); };
$scope.reportbydateresouce={src:"localhost/test/public/getreportsdata/1"}
Any idea ?
1- Injecting $sce with providers
.controller('CheckReportsCtrl', CheckReportsCtrl);
CheckReportsCtrl.$inject=['$scope','$http','$filter','$sce'] ;
2- I was including angular.min.js angularjs.js and angular.js i removed the angularjs.js from version 1.5.8 and problem solved.

CakePHP HTML Helper not working with Images

I have been developing a website in CakePHP 2.5.6 and have suddenly had an issue where when using $this->Html->Image(''); the image wont display on the page and I get this error if I go to the Image URL Directly:
Missing Controller
Error: ImgController could not be found.
Error: Create the class ImgController below in file: app/Controller/ImgController.php
<?php
class ImgController extends AppController {
}
Notice: If you want to customize this error message, create app/View/Errors/missing_controller.ctp
As I haven't been using CakePHP for long im not sure where to start with resolving this, its never done this before to me.
Any help would be appreciated,
Steve
EDIT:
The example I have been using is this:
<?php echo $this->Html->image('cake.power.gif');?>
it returns the following:
<img src="/trunk/img/cake.power.gif" alt="" />
I have checked and the image does exist on my server in the directory app/webroot/img/cake.power.gif

Resources