<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Selenium &#8211; CodePills.com</title>
	<atom:link href="https://codepills.com/tag/selenium/feed/" rel="self" type="application/rss+xml" />
	<link>https://codepills.com</link>
	<description>Helping you make a better code</description>
	<lastBuildDate>Sat, 29 Jan 2022 09:12:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>Selenium &#8211; remove html element from the DOM</title>
		<link>https://codepills.com/selenium-remove-html-element-from-the-dom/</link>
					<comments>https://codepills.com/selenium-remove-html-element-from-the-dom/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Mon, 03 Jan 2022 08:58:53 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[drivers]]></category>
		<category><![CDATA[finviz.com]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Selenium]]></category>
		<category><![CDATA[stocks]]></category>
		<category><![CDATA[time-series]]></category>
		<category><![CDATA[web-scrapper]]></category>
		<guid isPermaLink="false">https://codepills.com/?p=1280</guid>

					<description><![CDATA[This article will show you how to remove elements from <b>HTML DOM</b> (Document Object Model) when using automated web-browser framework <b>Selenium</b>. <a href="https://codepills.com/selenium-remove-html-element-from-the-dom/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>This article will show you how to remove elements from <b>HTML DOM</b> (Document Object Model) when using automated web-browser framework <b>Selenium</b>. If you want to remove anything you do not want on your site during web-scraping, you came to the right Selenium tutorial.</p>
<p><span id="more-1280"></span></p>
<h2>Introduction</h2>
<p>Let&#8217;s start with a practical example of removing elements from DOM. Imagine scrapping a website with <b>Selenium</b> and taking a screenshot of the page. However, the timed modal window will unannounced pop up when Selenium&#8217;s driver spin the browser window. So it is probably a good idea to remove the window before taking a picture in such a case.</p>
<p>When scrapping sites, removing excessive advertisement and disturbing elements is hard enough. But pop-up windows in the wrong moments are an overall user experience nowadays on many sites and blogs.</p>
<p>For example, we want to scrap stock time-series from famous sites like finviz.com. Unfortunately, after the first few seconds on the page, the cookies modal window pop-up and block the stock graph. Therefore, I will need to remove the cookie allowance modal window to take a clear screenshot.</p>
<div id="attachment_1281" style="width: 650px" class="wp-caption alignnone"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-1281" src="https://codepills.com/wp-content/uploads/2022/01/finviz_cookie_popup-1024x768.png" alt="Finviz.com cookie popup window" width="640" height="480" class="size-large wp-image-1281" srcset="https://codepills.com/wp-content/uploads/2022/01/finviz_cookie_popup-1024x768.png 1024w, https://codepills.com/wp-content/uploads/2022/01/finviz_cookie_popup-300x225.png 300w, https://codepills.com/wp-content/uploads/2022/01/finviz_cookie_popup-768x576.png 768w, https://codepills.com/wp-content/uploads/2022/01/finviz_cookie_popup.png 1098w" sizes="(max-width: 640px) 100vw, 640px" /><p id="caption-attachment-1281" class="wp-caption-text">Finviz.com cookie popup window</p></div>
<p>Let me show you two different ways to remove elements from Selenium&#8217;s HTML DOM. One way will be about eliminating parts that load with the page load and can be removed immediately. The second way will require calling <i>WebDriverWait</i> instance, and the way will be used for elements that pop up or load to page letter.</p>
<p>However, both options do not remove the element from the DOM. Instead, they hide it and make it invisible in the Selenium web driver.</p>
<h2>Remove elements from Selenium&#8217;s DOM without waiting</h2>
<pre><code class="language-java">FirefoxOptions options = new FirefoxOptions();
options.addArguments("-width=1920");
options.addArguments("-height=1080");
FirefoxDriver driver = new FirefoxDriver(options);

String stock = "T"; // AT&T Inc.
driver.get("https://finviz.com/quote.ashx?t=" + stock + "&ty=c&ta=1&p=d");

driver.executeScript("return document.getElementsByClassName('snapshot-table2')[0].remove();");</code></pre>
<p>If we look at the code, it might look straightforward. But I will go through it briefly. Initially, we set options for our Selenium Driver. Then, we pick Firefox as Selenium driver and put options (browser windows dimensions) into the driver itself.</p>
<p>After setting drivers options and instantiating Firefox drivers, we are clear to the call page in Firefox. We call finviz.com stock page for AT&#038;T Inc. company. The page which is loaded is immediately available for changes. If we want to remove any element we do not like, we can call script execution upon the loaded HTML DOM. We call executed script, which will remove the first  (0-th) element of the specific class name. It will be the first data table under the stock time-series graph.</p>
<p><b>Note</b> : If you have better idea for elements removal from Selenium&#8217;s HTML DOM, let me know in comments below.</p>
<h2>Remove elements from Selenium&#8217;s DOM with waiting</h2>
<pre><code class="language-java">FirefoxOptions options = new FirefoxOptions();
options.addArguments("-width=1920");
options.addArguments("-height=1080");
FirefoxDriver driver = new FirefoxDriver(options);

String stock = "T"; // AT&T Inc.
driver.get("https://finviz.com/quote.ashx?t=" + stock + "&ty=c&ta=1&p=d");

WebDriverWait wait = new WebDriverWait(driver, 10);

WebElement cookieWindow = wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("ConsentManager__Overlay-np32r2-0")));
driver.executeScript("return arguments[0].remove();", cookieWindow);</code></pre>
<p>The code above looks straightforward also. Initially, we set options for our Selenium Driver and picked Firefox as Selenium driver.</p>
<p>After setting drivers options and instantiating Firefox driver, we are clear to the call page in Firefox. We call the finviz.com stock page for AT&#038;T Inc. company and wait for 10 seconds or until HTML DOM does not contain an element with a specific class name. If it does, we will execute the script upon it, which will remove the first (the 0-th) element when it is found. Action means removing the whole pop-up modal window that appeared in the first 10 seconds of finviz.com page duration.</p>
<p>Class name &#8220;ConsentManager__Overlay-np32r2-0&#8221; is class name of pop-up cookie modal window. However, this class name might and surely will change in the future. So I would not rely on it for 100%. But for now, it serves our purpose.</p>
<h2>Conclusion</h2>
<p>This article has shown how remove elements from <b>HTML DOM</b> when using automated web-browser framework <b>Selenium</b>. Articles provide two different ways how to remove element on the page. Elements which load with page load can be removed immediately, without calling <i>WebDriverWait</i> instance. However, elements which pop-up or load to page letter needs to be removed with help of <i>WebDriverWait</i> instance.</p>
<p>However, if you look better, code snippets in the article can help you to build your Selenium web-scrapper 😉</p>
<p>Did you find element removal easy? Do you have your trick or know another way <u>how to remove elements from HTML DOM in Selenium</u>? Let us know in the comments below the article. We would like to hear your ideas and stories, and you might help others as well.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/selenium-remove-html-element-from-the-dom/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How To Start With Codeception PHP Framework And Selenium</title>
		<link>https://codepills.com/how-to-start-with-codeception-php-framework-and-selenium/</link>
					<comments>https://codepills.com/how-to-start-with-codeception-php-framework-and-selenium/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Wed, 09 Nov 2016 20:12:29 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Composer]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP framework]]></category>
		<category><![CDATA[Selenium]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[UAT]]></category>
		<category><![CDATA[webdriver]]></category>
		<guid isPermaLink="false">http://codekopf.com/?p=625</guid>

					<description><![CDATA[This is a small guide explaining how to start with Codeception PHP test framework and how to integrate it with Selenium for automated tests. <a href="https://codepills.com/how-to-start-with-codeception-php-framework-and-selenium/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>Recently I have been working on one job interview with test case requiring to write portion of automatized tests in Codeception PHP framework. Since I didn&#8217;t have any experience with Codeception PHP framework I needed to learn quickly as much as I could.</p>
<p><span id="more-625"></span></p>
<p>This is a small guide explaining how to start with Codeception PHP test framework and how to integrate it with Selenium for automated tests.</p>
<h2>What is Codeception and what is good for?</h2>
<p><a href="http://codeception.com/" target="_blank">Codeception</a> is PHP framework devoted to test PHP code. Installation is very simple and requires only a few steps. It is actually well known for its easy code readability of test units. Codeception PHP framework is used for acceptance testing. Codeception emphasize usage of the variable name $I, so than many lines of code are very descriptive exp. $I want to do this and that, $I expect to see something. etc.</p>
<p>Codeception helps with creating test suites for 3 types of testing:</p>
<ul>
<li>Accaptance</li>
<li>Unit</li>
<li>Functional</li>
</ul>
<h3><strong>What is acceptance testing?</strong></h3>
<p>Acceptance tests are emulating behavior of a real user visiting website.</p>
<blockquote><p>Acceptance testing is formal testing with respect to user needs, requirements, and business processes conducted to determine whether a system satisfies the acceptance criteria and to enable the user, customers or other authorized entity to determine whether or not to accept the system. Acceptance testing is also known as user acceptance testing (UAT), end-user testing, operational acceptance testing or field (acceptance) testing.</p>
<p>Source: Wikipedia</p></blockquote>
<p>First of all I have to recommend to watch first video by Jeffrey Way from EnvatoTuts+ for Codeception series <a title="Modern Testing in PHP with Codeception at EnvatoTuts+" href="https://code.tutsplus.com/courses/modern-testing-in-php-with-codeception" target="_blank" rel="nofollow">Modern Testing in PHP with Codeception</a>. Although the first video is very well narrated and instructive for beginner, rest of the serie is not and I would not recommend to pay for premium account to watch the rest. Jeffrey expect knowledge of many related topics where you can use Codeception (DB connection, Laravel, &#8230;) but do not create simple code snippets for your first test and does not talk much about usage of elemental Codeception functions. Serie is aimed for advanced users.</p>
<h2>1. Download</h2>
<p>You can download Codeception framework out of the box via composer by CLI command <code>$ composer require "codeception/codeception"</code> .</p>
<p>You can also implement it into already existing project updating a composer.json file placing following:</p>
<pre class="lang:js decode:true">{
    "require": {
        "codeception/codeception": "^2.2",
        ...
    }
}
</pre>
<p>For newest version of Codeception please visit and search <a title="PHP packages" href="https://packagist.org/" target="_blank" rel="nofollow">packagist.org</a> . Over CLI just hit composer command in folder of your project: <code>composer update</code> (or <code>composer install)</code>.</p>
<h2>2. Create codeception.yml</h2>
<p>By executing <code>codecept bootstrap</code> Codeception creates the codeception.yml file and bunch of new files for test suites.</p>
<h3>What is test suite?</h3>
<blockquote><p>The test suite is a collection of test cases that are intended to be used to test a software program to show that it has some specified set of behaviours. A test suite often contains detailed instructions or goals for each collection of test cases and information on the system configuration to be used during testing. A group of test cases may also contain prerequisite states or steps, and descriptions of the following tests.</p>
<p>Collections of test cases are sometimes incorrectly termed a <span style="text-decoration: underline;">test plan</span>, a <span style="text-decoration: underline;">test script</span>, or even a <span style="text-decoration: underline;">test scenario</span>.</p>
<p style="text-align: left;">Source: <a href="https://en.wikipedia.org/wiki/Test_suite" target="_blank">Wikipedia</a></p>
</blockquote>
<h2>3. Create your first test</h2>
<p>Create your first test by Codeception command:</p>
<p><code>codecept generate:cept acceptance FirstTest</code></p>
<p>Note: Codeception scenario tests are called Cepts.</p>
<h2>4. Setting Acceptance test method</h2>
<p>Basically there are 2 method which I managed to try to in short time &#8211; PHP Browser and Selenium WebDriver:</p>
<ol style="list-style-type: upper-alpha;">
<li>PHP Browser &#8211; works on idea of web scrapper. Code does not emulate real browser but just download HTML code and apply test scenarios on it.</li>
<li><a href="http://www.seleniumhq.org/projects/webdriver/" target="_blank">Selenium WebDriver</a> &#8211; works as &#8220;artificial user&#8221;. PHP test case code emulate real browser and perform actions upon real website in browser.</li>
</ol>
<p>I would recommended to first start with PHP Browser and than try Selenium WebDriver. PHP Browser can check HTML page contents, click links, fill forms, and submit POST and GET requests. Unfortunately PHP Browser have few drawbacks (you can click only on links with valid urls or form submit buttons,  you can’t fill fields that are not inside a form, you can’t work with JavaScript interactions like modal windows or date-pickers) and for more complex tests is necessary to use Selenium WebDriver.</p>
<h3>4.1. PHP Browser</h3>
<p>For setting up PHP Browser just change acceptance.suite.yml to:</p>
<pre class="lang:yaml decode:true">class_name: AcceptanceTester
modules:
    enabled:
        - PhpBrowser:
            url: "http://localhost/app"          
        - \Helper\Acceptance</pre>
<h3>4.2. Selenium WebDriver</h3>
<p>For setting Selenium WebDriver you need to make 3 steps.</p>
<p>1) Change acceptance.suite.yml to:</p>
<pre class="lang:yaml decode:true">class_name: AcceptanceTester
modules:
    enabled:
        - WebDriver:
            url: "http://localhost:8000/app"
            browser: firefox            
        - \Helper\Acceptance</pre>
<p>2) In your .bash_profile you must also set GeckoDriver (drivers emulating Firefox) which you can download from <a href="https://github.com/mozilla/geckodriver/releases" target="_blank">mozilla/geckodriver</a> GitHub page.</p>
<pre class="lang:default decode:true">## Selenium GeckoDriver
export PATH=$PATH:/PATH_TO_GECKODRIVER_FOLDER/</pre>
<p>3) To set Selenium WebDriver is also necessary download <a href="http://www.seleniumhq.org/download/" target="_blank">Selenium Server</a> and run it prior the test. To run Selenium Server change directory to folder where is file located and type server run command <code>java -jar selenium-server-standalone-<em>YOUR.V.NO</em>.jar</code> .</p>
<h2>5 .Writing first PHP test</h2>
<p>Under acceptance folder we will create first test in FirstTest.php file. We will try to check &#8220;Hello World!&#8221; text at homepage:</p>
<pre class="lang:php decode:true">&lt;?php
  $I = new AcceptanceTester($scenario);
  $I-&gt;wantTo('Test Frontpage');
  $I-&gt;amOnPage('/');
  $I-&gt;see('Hello World!', 'h1');
?&gt;</pre>
<h2>6. Running the test</h2>
<p>Running the test case is possible by simple command <code>codecept run</code> . You will write this command often so you can create temporary (alias in your folder) or permanent alias (in .bash_profile) by creating alias exp. <code>alias runtest=vendor/bin/codecept run</code> and than just type your alias.</p>
<p>If you have done everything right, with Selenium you should new see Firefox window executing your first test. After finishing it, browser will close down and terminal shows announcement about Success. PHP Webdriver execute all test just over the terminal info panel.</p>
<h3>6.1 Further use</h3>
<p>To show the list of all available commands you need to type <code>vendor/bin/codecept</code> . It will also handy to create alias for it ( but just for <code>vendor/bin/ </code>and than type<code> codecept</code> ).</p>
<p>Codecept will always by run execute every single test you have wrote all together. It helps to nerrow down only the test suite which we want by selecting test suit in command: <code>codecept acceptance/functional/unit run</code> .</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/how-to-start-with-codeception-php-framework-and-selenium/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
