Check box is not checked using xpath, it opens link - selenium-webdriver

Please see attached screen shots
using xpath "//div[#id='divTermsNdConditions']/div/div/div/label" it clicks on the label and open term and condition link
If use input id 'IsAgreeToNorms' then element is not visible/reachable.
What will be the solution to click on check box and checked?

You can try to click it with Explicit Wait,
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[#data-val-required="Your String Value"]")));
You can use any attribute value if its unique,
//input[#data-val-required="Your attribute Value"]
//input[#name="Your attribute Value"]
You can also use, ExpectedConditions.elementToBeClickable

Related

How to locate the XPATH of the Continue button on LinkedIn?

I right clicked the button, selected "Inspect" command and copied and used both XPATH and full XPATH. Neither of them worked for any of the commands below.
xpath = '//*[#id="ember949"]/footer/button[1]'
xpath_full = '/html/body/div[3]/div/div[2]/artdeco-tabs/artdeco-tabpanel[2]/form/footer/button[1]'
button = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, xpath)))
button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, xpath_full)))
Can someone please explain? Thank you.
Without the HTML, I cannot give a definitive answer.
Looks like the first id may be dynamic and could change.
As for the second one, the full XPaths are brittle and I do not use them at all.
There could be an iframe that you should switch to first.
You could try searching the entire page for a button element with the continue-btn class:
//button[#class='continue-btn']
I would recommend using the Selector / CSS Selector. In the code just change
By.XPATH
to:
By.CSS_SELECTOR
and instead of copying the XPATH copy the Selector or in some cases CSS Selector.

Web Crawlling A Site made in AngularJS

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')

How do i select an element from a google drop down in selenium?

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.

Webdriver and push button

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();

WebDriver: how to wait for text to disappear in the element

I have a field that dynamically changes it's text. I need a way to wait for the text to be changed. I'm not aware about what text will appear, but I know what text is currently there. So i'd like to wait for it to disappear in the element. Is there a way for this?
You can Try ExpectedConditions function textToBePresentInElement and add a not, like,
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement element = driver.findElement(By.id("foo"));
wait.until(ExpectedConditions.not(
ExpectedConditions.textToBePresentInElement(element,"textToBePresent")));

Resources