https://mahabhulekh.maharashtra.gov.in/ click on the link to see the site
I want to download a file from a site made in Angularjs. On first page there are 6 links which I have to crawl one by one. Selecting any link will lead to a page having 3 Dropdown.
Select District from dropdown which lead to related talukas in second dropdown.
Select Taluka from dropdown which lead to related Villages in third dropdown.
Select Village.
Now there is radio buttons from which I have to select the one which has survey number.
Now have to insert some digits and Click on Button. Now on the same page a dropdown will be shown from which I have to select all the options one by one and Click on button, the related file will get downloaded in pop up, so have to allow popups.
Code I have done is in selenium. I have just Clicked on the link on first page and traversed to second but now have to select dropdown but dont know how to do this as this site used Angularjs
System.setProperty("webdriver.chrome.driver","D:\\chromedriver1.exe");
WebDriver driver = new ChromeDriver();
final NgWebDriver ngDriver;
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
String baseUrl = "https://mahabhulekh.maharashtra.gov.in/";
// launch Fire fox and direct it to the Base URL
driver.get(baseUrl);
driver.findElement(By.partialLinkText("अमरावती")).click();
There's really nothing special about this being built with AngularJS. You don't show what you've tried after clicking on the link from the first page, so i'm guessing that you just need some guidance of what to do next.
If you inspect the new page, you'll see that there is a "select" webElement that you need to interact with. (be sure to use WebDriverWait to wait for the control to be available). There is a convenience class for interacting with these elements:
from selenium.webdriver.support.ui import Select
Here's the first dropdown:
dist_select = Select(driver.find_element_by_id('distSelect'))
select.select_by_value('string:5')
Related
I have a field where it picks the location from a dropdown which is from google dropdown and not a native dropdown. So how can i click on that element in dropdown using selenium.
The results are show in an HTML div. The only reason why you are not able to find this div in HTML is because it appears somewhere near the bottom of the HTML and it is fragile enough to get dismissed with a click anywhere.
Coming to the code, your search results are generated inside individual divs with id="pac-item". So you have to just find them and click which ever item you want. Please don't forget to mark the answer
WebDriver driver = new ChromeDriver();
driver.get("http://www.nobroker.in/");
driver.findElement(By.id("locationGoogle")).sendKeys("n");
Thread.sleep(4000);
List<WebElement> elements = driver.findElements(By.className("pac-item"));
for(WebElement element : elements)
{
System.out.println(element.getAttribute("innerHTML"));
if(element.getAttribute("innerHTML").contains("Sopara"))
{
element.click();
}
}
Of course you will update the code to make it more efficient.
i try to make in webdriver a test.
go to http://programyedukacyjne.pl/konkurs/galeria-prac.html
click for example first vote "GŁOSUJ [star]"
and should appear a box to put email.
But nothing happend just add to url in browser "#vote_box_22"
I tryed use click(), Action and javascript click but still there no appear a form...
here is begine:
driver.get("http://programyedukacyjne.pl/konkurs/galeria-prac.html");
WebElement location = driver.findElement(By.name("filter_miejscowosc"));
location.sendKeys("nowy sącz", Keys.ENTER);
here is where I have problem
WebElement voteBtn = driver.findElement(By.xpath("html/body/div[4]/div/div[3]/div/div[4]/div/div[1]/div[2]/div[2]/div[1]/a"));
voteBtn.click();
my secound solution
new Actions(driver).moveToElement(voteBtn).click().perform();
Try using a more specific selector that pinpoints the link more accurately in a less brittle way. The following CSS selector should select the vote link for the first result shown in the list:
WebElement voteBtn = driver.findElement(By.cssSelector("div.praca:nth-of-type(1) a[href*='vote_box']"));
voteBtn.click();
I had a problem with the web driver while page get refresh
scenario:
click on the 1st button and the page got refresh. Once the page refresh, then the driver cant able to find the position of the second button. the second button is save function so that I cant able to save that page.
The error which I got while running :
unknown error: Element is not clickable at point (257, 898).
Other element would receive the click:
<div id="divModel" class="dialog" style="display: block; height: 2037px; width: 1450px;">...</div>
1) is there any solution to refresh the variables on the page without refreshing the whole page?
2) is there any solution to find out the next button position after clicking the first one on that page?
First of all, as we do not have any clear idea what happens with you. First thing checks that is your Xpath is changing after refreshing the page. another thing is may be your page need some wait.
Try below code:-
WebElement element= driver.findElement(By.xpath("YOUR XPATH OR ANY LOCATOR"));
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated((By) element));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);
At last if nothing work then try to use Thread.sleep(5000); .
It's not a good practice even it is not recommended to use Thread.sleep but you can at least try once to ensure that the problem is related to wait only
It's not a solution, it's workaround: if you use Chrome driver then use FF/IE driver instead. I encountered similar problem with Chrome driver not so long ago, turned out to be Chrome driver bug.
Also, if you use PO model, you can use #CacheLookup annotation:
#CacheLookup
#FindBy(id = "your_id")
private WebElement saveButton;
Marker annotation to be applied to WebElements to indicate that it
never changes (that is, that the same instance in the DOM will always
be used)
I am trying to upload a file through selenium webDriver but selenium gives an error:Unable to locate element. I have used all method to find element and click on browse but not any click occurring on that.
The HTML is <input type="file" onmousedown="this.blur();" onclick="//this.blur();" onchange="$('file-loader').show(); this.form.submit();" name="metadata_item" id="metadata_item">
First check the input element is visible
Then, you don't have to click on the browse button, it will trigger an OS level dialogue box and effectively stop your test dead.
In order to deal with this follow this code:
driver.findElement(By.id("myElementId")).sendKeys("<pathToFile>");
myElementId is the id of that element (button in this case) and in sendKeys you have to specify the absolute path of the content you want to upload. The Webdriver will do the rest for you.
Keep in mind that the upload will work only If the element you send a file should be in the form
cant answer without HTML code.
in order to click Browse button place the pointer in previous field i.e,
email address field and use
Robot robot=new Robot();
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
and then a system popup displays then use AutoIT tool to handle it
It could be under another frame.
Try switching to that frame and click the element.
It would work.
For Example - If the browse button is under another frame which has Id = "frameUpload", then switch the webdriver to that frame like this:
driver.switchTo().frame("frameUpload");
Now click on the browse button like this:
driver.findElement(By.Id("Id of the button")).click();
once you are done with the click, you can always get back to the default window like this
driver.switchTo().DefaultContent();
I'm having trouble trying to click on on a button within a form.
I've tried xpath, cssselector, className, id, but still cannot find it.
Here's the HTML snippet for the button:
<input type="button" value="Continue" id="ni-reg-btn-register" class="btnNext ni-reg-btn-register">
I'm using WebDriver in Java
Getting this trace:
org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 30.09 seconds
Frequency: 100%
Browser: Firefox
URL: https://subscription.thetimes.co.uk/webjourney/webj_capturecustomerdetails
I've tried each of the following lines of code one by one (but no luck):
driver.findElement(By.className("btnNext ni-reg-btn-register")).click();
driver.findElement(By.cssSelector("buttons#ni-reg-btn-register.btnNext ni-reg-btn-register")).click();
List<WebElement> buttonlist= driver.findElements(By.className("btnNext ni-reg-btn-register"));
driver.findElement(By.id("ni-reg-btn-register")).click();
driver.findElement(By.xpath("//*[#id="ni-reg-btn-register"]")).click();
I was able to click the Continue Button using the below xpath.
//input[#id='ni-reg-btn-register']
I would suggest trying a WebDriverWait call to wait for the element in question to exist on the page prior to interacting with it. The Java documentation can be found here. It appears that while you are using the correct locator and your page is working, there is a timing issue where Selenium is trying to access the element prior to it being loaded.
EDIT: I was unable to locate an element on the provided page with the supplied id. I assume I am missing a step, but I did a search on the HTML for that page and found nothing.
I dont find the above button on the page link you provided ..
better chk the page link and try to give some wait statement after page load ...
implicit wait would be better or simpli Thread.sleep(2000);