Hi can any please tell how to run this sample program with HTMLUNIT DRIVER INSTEAD OF FIREFOX DRIVER.
The below code had run successfully with firefox driver but did not run successfully with htmlunit driver giving
org.openqa.selenium.NoSuchElementException: Unable to locate a node using .//*[contains(concat(' ',normalize-space(#class),' '),' gssb_e ')]-EXCEPTION.
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class GoogleSuggest
{
public static void main(String[] args) throws Exception
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com/webhp?complete=1&hl=en");
WebElement query = driver.findElement(By.name("q"));
query.sendKeys("Cheese");
long end = System.currentTimeMillis() + 50000;
while (System.currentTimeMillis() < end)
{
WebElement resultsDiv = driver.findElement(By.className("gssb_e"));
if (resultsDiv.isDisplayed())
{
break;
}
}
List<WebElement> allSuggestions =
driver.findElements(By.xpath("//td[#class='gssb_a gbqfsf']"));
for (WebElement suggestion : allSuggestions)
{
System.out.println(suggestion.getText());
}
}
}
Please any one tell me how to do it with HTMLUNIT driver n I M A VERY JUST BEGINNER and explain me the reason even and i would be happy if any one post the same code manipulated with HTMLUNIT driver and also please tell me how to overcome the DEFAULTCSSERROR when using HTMLUNIT driver which was again not a problem with firefox driver.
My main intention is dat running the above process backside with out invoking the browser making all things invisible.
Any one please do help me in this aspect.
In HtmlUnit Driver, It'll look for only lowercase tag and attribute.
Example :
Html
input type="text" name="example" >
INPUT type="text" name="other" >
// webdriver code
driver.findElements(By.xpath("//input"));
for HtlmUNit case:It'll find only one element(name="example")
for firefoxDriver case = it'll find 2 element
hope it'll you in debugging code
HtmlUnit driver <> FirefoxDriver
"If you test javascript using HtmlUnit the results
may differ significantly from those browsers"
Take a look here
Related
I am new to the web crawling task. Previously I tried the following simple crawler, and it worked well.
Recently I come back to the code and tried to do more on crawler, however the browser.find_element_by_id("lst-ib") does not work and I receive the error that says
' no such element: Unable to locate element: {"method":"css selector","selector":"[id="lst-ib"]"}
(Session info: chrome=84.0.4147.89) '
To solve my problem, I tried to find xpath of input text box for google page from inspect. Is it always like that? does the id or css selector that we define for crawler change regularly and we should update the code?
from selenium import webdriver
url = "https://www.google.com"
browser = webdriver.Chrome(executable_path = "chromedriver")
browser.get(url)
#inputElement = browser.find_element_by_id("lst-ib")
# I replace the xpath with previous id
inputElement =
browser.find_element_by_xpath("/html/body/div/div[2]/form/div[2]/div[1]/div[1]/div/div[2]/input")
inputElement.send_keys("my input search text")
inputElement.submit()
browser.quit()
try below xpath :
inputElement =
browser.find_element_by_xpath("//body[#id='gsr']/div[#id='viewport']/div[#id='searchform']/form[#id='tsf']/div/div/div/div/div/input[1]")
inputElement.send_keys("my input search text")
Your solution:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import time
driver = webdriver.Chrome(executable_path=r"path of chrome driver")
wait = WebDriverWait(driver, 10)
driver.get("https://www.google.com")
inputElement = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "/html/body/div/div[2]/form/div[2]/div[1]/div[1]/div/div[2]/input")))
inputElement.send_keys("my input search text")
Output :
I am new to .net core.
How can I auto fill forms and submit in dotnet core ?
Please find following sample URLs I want to try
https://mparivahan.in/uyt/?pur_cd=102
Value - 1 = "MH1R"
Value - 2 = "5656"
https://www.filegstrstnow.com/searchGSTTaxpayer
sample Value = "24AADCS0852Q1Z2"
With Regards
I guess you want to automate operations in browser. For this purpose you need a browser automation framework which can be used in you .NET Core 2.0 code. Something like Selenium WebDriver. In this case you code will look like this:
[Test]
public void TestWithFirefoxDriver()
{
using (var driver = new FirefoxDriver())
{
driver.Navigate().GoToUrl(#"https://parivahan.gov.in/rcdlstatus/?pur_cd=102");
driver.FindElement(By.Id("form_rcdl:tf_reg_no1")).Send("GJ01RR");
driver.FindElement(By.Id("form_rcdl:tf_reg_no2")).Send("5656");
driver.FindElement(By.Id("form_rcdl:j_idt36")).Click();
var wait = new WebDriverWait(driver, TimeSpan.FromMinutes(1));
// Find element with the result to retrieve value, and so on..
}
}
Note: I didn't check the code above in runtime, it is just for demonstration purposes.
To run Selenium automation code without opening the browser you could use PhantomJS driver instead of drivers for real browsers like FirefoxDriver. Change this line:
using (var driver = new FirefoxDriver())
to:
using (var driver = new PhantomJSDriver())
I use WebDriver and ChromeDriver. How i can fetch text from second table?
I have two tables.
1: click to see photo
2: click to see photo
So, When i try download data from second table i download from first :/
WebElement baseTable = driver.findElement(By.className("grey"));
List<WebElement> tableRows = baseTable.findElements(By.tagName("tr"));
JOptionPane.showMessageDialog(null, tableRows.get(1).getText());
Thank you for your help !
You can use xpath line this for this 'Actualny tryb'
//td[contains(#class,'strong'][contains(text(),'Actualny tryb')]
for this Rejestracja
//img[contains(#style,'vertical-align:middle')][contains(text(),'Rejestracja bezpo')]
Try this code, I don't know JOptionPane:
driver.get("https://www.usosweb.uj.edu.pl/kontroler.php?_action=katalog2/przedmioty/rejestracjaNaPrzedmiotCyklu&prz_kod=WOZ.PLD-3SDHTTP&cdyd_kod=17%2F18&callback=g_21a73193");
String s = driver.findElement(By.xpath("//td[contains(text(),'Status rejestracji przedmiotu')]")).getText();
System.out.println(s);
JOptionPane.showMessageDialog(null, s);
will someone try?
You need download selenium jar from:
http://selenium-release.storage.googleapis.com/3.5/selenium-server-standalone-3.5.3.jar
Download chromedriver: https://chromedriver.storage.googleapis.com/2.32/chromedriver_win32.zip
Import jar file
and copy code:
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://www.usosweb.uj.edu.pl/kontroler.php?_action=katalog2/przedmioty/rejestracjaNaPrzedmiotCyklu&prz_kod=WOZ.PLD-3SDHTTP&cdyd_kod=17%2F18&callback=g_21a73193");
Wait();
String s = driver.findElement(By.xpath("//img[contains(#style,'vertical-align:middle)][contains(text(),'Rejestracja bezpo')]")).getText();
JOptionPane.showMessageDialog(null, s);
Warm Greetings!!
I am trying to click on a date value from the data window popped up after clicking on the datepicker but I am getting No Element Found Exception.
I have gone thru all possible solutions present in dis forum but seems none satisfy my need.
Below is the code:
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http:www.makemytrip.com/flights";
driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
driver.manage().window().maximize();
}
public void testFlip1() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.cssSelector(".ui-button.ui-widget.ui-state-default.ui-button-text-only.ui-corner-left.ui-state-active")).click();
driver.findElement(By.cssSelector(".flL:nth-of-type(2)>.ui-combobox>input")).sendKeys("New Delhi, India (DEL)");
driver.findElement(By.cssSelector(".flL:nth-of-type(3)>.ui-combobox>input")).sendKeys("Mumbai, India (BOM)");
driver.findElement(By.cssSelector("a.date_field_tab.flL.make_relative.left")).click();*
Until here the calender gets expanded and the issue starts next when I am trying to select a date.
driver.findElement(By.xpath("//*[#id='ui-datepicker-div']/div[3]/table/tbody/tr/td/a[text()='30']")).click();
The above xpath works properly in IDE and selects the value.But its not working in webdriver.
Kindly help me to get the solution.
I came across a similar issue, setting the date Via JavaScript helped.
javaScriptExe("$(\"input[Rel='Due Date']\").removeAttr('readonly').removeAttr('hidden').
val('"23 May 2015"')");
I created a button that looks up the coordinates of the device. There is no errors in the code but for some reason which is eluding me, the event is not being triggered.
Here is my code:
protected function lblCheckIn_clickHandler(event:MouseEvent):void
{
if (Geolocation.isSupported)
{
lblLat.text = "Finding Location...";
geo.addEventListener(GeolocationEvent.UPDATE, onUpdate);
}
else
{
lblLat.text = "Geolocation is not supported on this device.";
}
}
Later on I have the event code:
protected function onUpdate(event:GeolocationEvent):void
{
if (event.horizontalAccuracy <= 10)
{
Lat = event.latitude.toString();
Long = event.longitude.toString();
lblLat.text = Lat;
lblLong.text = Long;
geo.removeEventListener(GeolocationEvent.UPDATE, onUpdate);
navigator.pushView(PersonSelect);
}
else
{
lblLat.text = "Updating";
}
}
Oh, and I also did the usual imports
import flash.filesystem.File;
import flash.sensors.Geolocation;
import flash.events.GeolocationEvent
import spark.events.ViewNavigatorEvent
import flash.utils.ByteArray;
Any clues as to why my event isnt calling?
Have you instantiated an instance of geo?
if (Geolocation.isSupported)
{
lblLat.text = "Finding Location...";
geo = new Geolocation();
geo.addEventListener(GeolocationEvent.UPDATE, Update);
}
I worked out the ultimate cause of this specific problem. It stems from Flash Builder not installing the complete Android SDK or the IOS SDK. Once I manually installed these by copying the SDK folders to their correct paths in Adobe Flash Builder, my GPS events were called successfully.
To sum up, if you get this trouble where the code and everything looks alright but it wont call up your events, then check to make sure that your latest SDKs for Flex are installed correctly for Android and or iOS