Why switching to alert through selenium is not stable?

As per your code block there are a couple of issues which you need to address as follows : Switching to an Alert : The method switch_to_alert() is Deprecated and you should be using switch_to.alert instead. The API Docs clearly mentions the following : def switch_to_alert(self): “”” Deprecated use driver.switch_to.alert “”” warnings.warn(“use driver.switch_to.alert instead”, DeprecationWarning) … Read more

Is there a way to search webelement on a main window first, if not found, then start searching inside iframes?

Yes, you can write a loop to go through all the iframes if the element not present in the main window. Java Implementation: if (driver.findElements(By.xpath(“xpath goes here”).size()==0){ int size = driver.findElements(By.tagName(“iframe”)).size(); for(int iFrameCounter=0; iFrameCounter<=size; iFrameCounter++){ driver.switchTo().frame(iFrameCounter); if (driver.findElements(By.xpath(“xpath goes here”).size()>0){ System.out.println(“found the element in iframe:” + Integer.toString(iFrameCounter)); // perform the actions on element here } … Read more

selenium – Failed to execute ‘evaluate’ on ‘Document’: The string is not a valid XPath expression

This error message… SyntaxError: Failed to execute ‘evaluate’ on ‘Document’: The string ‘//span[contains(@class, ‘md_countryName_fdxiah8’ and text(), ‘Colombia’)]’ is not a valid XPath expression. …implies that the XPath which you have used was not a valid XPath expression. Seems you were pretty close. You can use either of the following Locator Strategies: Using xpath 1: country … Read more

Selenium can’t open a second page

options.add_experimental_option( “excludeSwitches”, [‘enable-automation’]) options.add_argument( “user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36”) options.add_argument(“–remote-debugging-port=9222”) driver = webdriver.Chrome(options=options) driver.get( “https://www.justdial.com/Chennai/Hr-Consultancy-Services/nct-10258625/page-2”) driver.set_page_load_timeout(30) driver.get( “https://www.justdial.com/Chennai/Hr-Consultancy-Services/nct-10258625/page-3”) the website is detecting automation use above code 🙂 You can also do this in single line Just add below argument: options.add_argument(‘–disable-blink-features=AutomationControlled’) disabling enable-automation , or disabling automation controller disables … Read more

How to retrieve partial text from a text node using Selenium and Python

To print text … you have to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies: Using CSS_SELECTOR, childNodes and strip(): print(driver.execute_script(‘return arguments[0].firstChild.textContent;’, WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, “a.call_recipe[href^=’/recipes’]”)))).strip()) Using XPATH, get_attribute() and splitlines(): print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, “//a[@class=”call_recipe” and starts-with(@href, ‘/recipes’)]”))).get_attribute(“innerHTML”).splitlines()[1]) Note : You have to add the following imports : from selenium.webdriver.support.ui … Read more

How to send text to the Password field within https://mail.protonmail.com registration page?

To send a character sequence to the Password field as the the desired element outside of the <iframe> so you have to: switch_to_default_content(). Induce WebDriverWait for the desired element to be clickable. You can use the following Locator Strategies: Code Block: chrome_options = webdriver.ChromeOptions() chrome_options.add_argument(“start-maximized”) #chrome_options.add_argument(‘disable-infobars’) driver = webdriver.Chrome(options=chrome_options, executable_path=r’C:\Utility\BrowserDrivers\chromedriver.exe’) driver.get(“https://protonmail.com/”) WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, “//a[@class=”btn btn-default … Read more

How to automate Google Home Page auto suggestion?

To extract the Auto Suggestions from the Search Box on Google Home Page you have to induce WebDriverWait for the visibilityOfAllElements and you can use the following solution: Code Block: import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class Google_Auto_Suggestions { public static void main(String[] args) … Read more

UnreachableBrowserException Caused by: java.lang.NullPointerException when “webdriver.firefox.marionette” is used

Here is the Answer to your Question: The error UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure says it all. As per guru99.com it is mentioned to use webdriver.firefox.marionette within System.setProperty. In Selenium 3.x we would be using webdriver.gecko.driver instead. So consider changing … Read more

How do you click on a checkbox from a list of checkboxes via Selenium/Webdriver in Java?

If you already know the id of the checkbox, you can use this method to click select it: string checkboxXPath = “//input[contains(@id, ‘lstCategory_0′)]” IWebElement elementToClick = driver.FindElement(By.XPath(checkboxXPath)); elementToClick.Click(); Assuming that you have several checkboxes on the page with similar ids, you may need to change ‘lstCategory_0’ to something more specific. This is written in C#, … Read more

selenium.common.exceptions.ElementNotVisibleException: Message: element not visible while trying to access an element with Python + Selenium

This error message… selenium.common.exceptions.ElementNotVisibleException: Message: element not visible …implies that the desired element was not visible within the HTML DOM while the WebDriver instance was trying to find it. ElementNotVisibleException ElementNotVisibleException is thrown when an element is present on the DOM Tree, but it is not visible, and so is not able to be interacted … Read more

tech