How to scrape jsp written web pages? - selenium

I want to automate the process of getting logged in to the website https://www.fois.indianrail.gov.in/foisweb/view/GG_LoginNew.jsp?txtProj=TMS%20ZONAL&clintId=? .
I have tried referencing all the text fields in the web page.
driver.get('https://www.fois.indianrail.gov.in/foisweb/view/GG_LoginNew.jsp?txtProj=TMS%20ZONAL&clintId=')
pot='//*[#id="txtUserId"]'
tom=driver.find_element_by_xpath(pot)
tom.send_keys('text')
mot='//*[#id="txtPassword"]'
pot=driver.find_element_by_xpath(mot)
pot.send_keys('text')
radio_point='//*[#id="txtOptnD"]'
iiu=driver.find_element_by_xpath(radio_point)
iiu.click()
location_point='//*[#id="txtLocation"]'
mp=driver.find_element_by_xpath(location_point)
mp.send_keys('text')
submit='//*[#id="Submit"]'
sub=driver.find_elements_by_xpath
sub.click()
I expect the username text field to be written as text but the error is
selenium.common.exceptions.NoSuchElementException: Message: Unable to
locate element: //*[#id="txtUserId"]

The element you are trying to access is inside a frame. You have to switch to that frame before accessing the elements.
Try This:
driver.get('https://www.fois.indianrail.gov.in/foisweb/view/GG_LoginNew.jsp?txtProj=TMS%20ZONAL&clintId=')
driver.switch_to.frame("frmCUMain")
driver.find_element_by_id("txtUserId").send_keys("text")
driver.find_element_by_id("txtPassword").send_keys("text")
driver.find_element_by_id("txtOptnD").click()
driver.find_element_by_id("txtLocation").send_keys("location")
driver.find_element_by_id("Submit").click()

Related

How to catch white screen or black screen using robotframework or selenium

My project is to catch certain error message that can possibly show on website using robot framework and selenium. such as 400 - 500 error messages.
ex: 404. page not found
But we cannot catch empty page like white screen or black screen.
Is there a way for robot/selenium to tell if the page is just all white or all black ? whith no text visible or any element visible.
Thanks
Just get the source and check any unique text or tag and use it in the place of "application-footer". In my case i used application-footer which is available in my source. So Use this below code to find blank page, this is the workaround I used
${Source}= Get Source
Log ${Source}
${Blank_status} = Run Keyword And Return Status Should Contain ${Source} application-footer
Run Keyword If "${Blank_status}" == "False" FAIL Displayed Empty Page
If you want to Handle Failure in your own way, then instead of FAIL keyword write your own keyword to Handle and call the keyword
Run Keyword If "${Blank_status}" == "False" Error_Handle
*** Keywords ***
Error_Handle
# write your handling code

InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression contains(text() error message

I'm getting this error message when selenium/C# program tried to click on an element in a drop down list in Dynamis365.
Inner Exception 1:
InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression contains(text(), 'Submitted') because of the following error:
TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type.
(Session info: chrome=87.0.4280.88)
My Code is:
internal void SetValues()
{
findByElement.FindByXPath("//span[contains(text(), 'Submission Pending')]").Click();
findByElement.FindByXPath("contains(text(), 'Submitted')").Click();
}
The HTML is:
<span id="id-bc19d003-2d6a-43ad-8e1b-566ecbb00647-132-statuscode6-statuscode.fieldControl-pickliststatus-comboBox_text-value" class=" ">Submission Pending</span>
I'm trying to click on Submitted choice, which do not show in HTML:DropDownList
Note: The other drop down list choices do not show in html. Only after making a choice (Submitted) it shows up in the html (replaces Submission Pending")
Submission Pending
Submitted clicked
Are you sure the page has fully loaded? Have you read the docs, specifically the 'waits' section (link below for the python version). I had this problem and simply put a 5 second delay into the code and it worked fine.
https://selenium-python.readthedocs.io/waits.html
Alternatively you may find it easier locating the element by id rather than by XPath
FindByXPath("contains(text(), 'Submitted')")
This is not a valid XPath expression! All XPath must start with the slash / character. Perhaps you meant something like:
FindByXPath("//*[contains(text(), 'Submitted')]")
Below line of code worked:
findByElement.FindByXPath("//*[./text()='Submitted']").Click();

Selenium script getting error 'value cannot be null parameter: source' after setting password textbox

I am getting an error "Value cannot be null,parameter name: s" after setting password through selenium script and clicking submit button.
Please help me on this, Thanks
Am using the below code for setting password
var passwordtxt=driver.FindElement(By.Id("txtpassword"));
var JSexecutor= (IJavaScriptExecutor)driver;
JSexecutor.ExecuteScript("arguments[0].setAttribute('value', arguments[1])",passwordtxt,"mypassword");
Based on the error message you provided, it sounds like the item passwordtxt doesn't exist on the page. Value cannot be null is referring to the element you pass into ExecuteScript, which is passwordtxt in this case.
To solve this problem, you will need to change the way you are finding passwordtxt. If you post some more HTML from your page's source, we can help you determine the correct selector to use.

The selenium got the different html source from my local pc

I fetched http://book.flypeach.com/default.aspx?ao=B2CZHTW&ori=TPE&des=KIX&dep=2015-06-12-undefined-undefined&adt=1&chd=0&inf=0&langculture=zh-TW&bLFF=false by driver.current_url
However I got timeout error by this code
wait = Selenium::WebDriver::Wait.new(:timeout => 10) # seconds
wait.until { #driver.find_element(:css => "div.WrapperFlightDate") }
But I can see the css attributes div.WrapperFlightDate was truly exsiting in the page_source,
How could it happen ?
When I opened given link and trying to see given class in source code(ctrl + u),I didn't find given class.May be page was not loaded properly.
I refreshed page and right click on page -> View Page Source option then got this class in source code.Even I also ran this successfully in FF.
I also surprised why I didn't see correct source code first time.
You also try same,hope so you also get correct code now :).

FPDF Fatal Error

I am trying to test implementation of FPDF. Below is the code I'm testing with, but it keeps giving me the error: "Fatal error: Class 'FPDF' not found in /home4/fwall/public_html/create-press-release.php on line 5". That is the URL to the page I am calling the below code on.
I have verified that the php file for FPDF is being required from the right spot, and it's still happening. Can anyone figure out what's going on?
require(__DIR__.'/fpdf.php'); //The fpdf folder is in my root directory.
//create a FPDF object
$pdf=new FPDF();
//set document properties
$pdf->SetAuthor('Lana Kovacevic');
$pdf->SetTitle('FPDF tutorial');
//set font for the entire document
$pdf->SetFont('Helvetica','B',20);
$pdf->SetTextColor(50,60,100);
//set up a page
$pdf->AddPage('P');
$pdf->SetDisplayMode(real,'default');
//insert an image and make it a link
//$pdf->Image('logo.png',10,20,33,0,' ','http://www.fpdf.org/');
//display the title with a border around it
$pdf->SetXY(50,20);
$pdf->SetDrawColor(50,60,100);
$pdf->Cell(100,10,'FPDF Tutorial',1,0,'C',0);
//Set x and y position for the main text, reduce font size and write content
$pdf->SetXY (10,50);
$pdf->SetFontSize(10);
$pdf->Write(5,'Congratulations! You have generated a PDF.');
//Output the document
$pdf->Output('example1.pdf','I');
This line:
require('http://siteurlredacted.com/fpdf/fpdf.php');
probably won't do what you expect. The request will make the remote server "execute" fpdf.php, returning a blank page, and your script will include an empty file. That is why it doesn't find any class to load.
You should download FPDF and put the file on your filesystem, where it is accesible to your script with no HTTP requests. You can try putting fpdf.php inside your project.
Hope this helps.