I am testing ordering from one tour operator. I have a problem with access to the button. I am not familiar with js, but it seems to me that the elements are generated by scripts. In general, I understand very little about how this page works. Give me a vector in which direction to go. Some items I can contact. For example, to those that are in the header page. But I need the "More Options" button. The very address of the page https://global.natalie-tours.ru/b2c/ you need to go to it from page https://www.natalie-tours.ru/ This is how I try to do it
public class OrderTest { private WebDriver driver; private String baseUrl; private StringBuffer verificationErrors = new StringBuffer(); @Before public void SetUp() throws Exception { System.setProperty("webdriver.gecko.driver", "C:\\Users\\egor\\Documents\\geckodriver.exe"); driver = new FirefoxDriver(); baseUrl = "https://www.natalie-tours.ru"; } @Test public void TestOrder() throws Exception{ this.driver.get(baseUrl); this.driver.manage().window().maximize(); WebElement countries = this.driver.findElement(By.id("countries")); countries.click(); Select dropdownCountry = new Select(countries); dropdownCountry.selectByValue("18"); WebElement myChosenCountry = dropdownCountry.getFirstSelectedOption(); myChosenCountry.sendKeys(Keys.ENTER); String parentHandle = this.driver.getWindowHandle(); WebElement selectZone = this.driver.findElement(By.id("zones")); selectZone.click(); Select dropdownZone = new Select((selectZone)); dropdownZone.selectByValue("16"); WebElement myChosenZone = dropdownZone.getFirstSelectedOption(); myChosenZone.sendKeys(Keys.ENTER); WebElement searchButton = this.driver.findElement(By.cssSelector("input[type=\"submit\"]")); searchButton.click(); Thread.sleep(10000); Set<String> windows = this.driver.getWindowHandles(); System.out.println(windows.size()); Iterator iterator = windows.iterator(); String currentWindowId; while (iterator.hasNext()){ currentWindowId = iterator.next().toString(); if (!currentWindowId.equals(parentHandle)){ this.driver.switchTo().window(currentWindowId); WebElement buttonOpt = this.driver.findElement(By.xpath("//*[@id=\"moreInfo1293951883\"]/button/span")); buttonOpt.click(); } } // WebElement choiceCountry = this.driver.findElement (By.className ("selinput"));
Thread.sleep(10000); } // @After // public void tearDown () throws Exception {// driver.quit (); // String verificationErrorString = verificationErrors.toString (); // if (! "". equals (verificationErrorString)) {// fail (verificationErrorString); //} //}
private boolean isElementPresent(By by) { try { driver.findElement(by); return true; } catch (NoSuchElementException e) { return false; } } private boolean isAlertPresent() { try { driver.switchTo().alert(); return true; } catch (NoAlertPresentException e) { return false; } } }