Induce WebDriverWait and elementToBeClickable to click on the element.
Try the following options.
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement selectGender = wait.until(ExpectedConditions.elementToBeClickable(By.id("id_gender1")));
selectGender.click()
OR
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement selectGender = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='radio-inline']/label[@for='id_gender1']")));
selectGender.click()
Answer from KunduK on Stack OverflowInduce WebDriverWait and elementToBeClickable to click on the element.
Try the following options.
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement selectGender = wait.until(ExpectedConditions.elementToBeClickable(By.id("id_gender1")));
selectGender.click()
OR
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement selectGender = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='radio-inline']/label[@for='id_gender1']")));
selectGender.click()
Here is your code
findElement(By.xpath("//input[@name='id_gender']")).click();
python - Selenium Issue - Unable to locate element: {"method":"css selector","selector" - Need help fixing this - Stack Overflow
no such element: Unable to locate element: {"method":"css selector","selector":".jobs-search-results"}
Message: no such element: Unable to locate element: {“method”:“css selector”,“selector”:“.syllable”}
Can you tell the website and what you wanna scrape?
More on reddit.compython - NoSuchElementException: no such element: Unable to locate element: css selector but im using find_element - Stack Overflow
You should try the answer on this page How can I find an element by CSS class with XPath?.
You should be able to do something close to your first answer by searching only for "marker-cluster-small." Hope it helps in some way.
So it would be
("//div[contains(@class, 'marker-cluster-small')]")
You can also find it by css:
driver.find_element(:css, '.leaflet-marker-icon.marker-cluster.marker-cluster-small.leaflet-clickable.leaflet-zoom-animated')
But in this case, conor's answer is best since class value is too much lengthy.
I want to get words from a site using selenium on python. Is there any way to do it? I've tried Xpath, class name and still nothing.
driver.find_element_by_class_name('syllable') driver.find_element_by_xpath('/html/body/div[2]/div[2]/div[2]/div[2]/div')
<div class="round"> <div class="syllable">gi</div> </div> So I want to get "gi". Thanks!
To click() on the button with text as Add Order you have to induce WebDriverWait for the element_to_be_clickable() you can use either of the following Locator Strategies:
Using
CSS_SELECTOR:WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[id^='button-'] > span.x-btn-wrap > span.x-btn-button > span.x-btn-inner.x-btn-inner-center"))).click()Using
XPATH:WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[starts-with(@id, 'button-')]/span[@class='x-btn-wrap']/span[@class='x-btn-button']/span[@class='x-btn-inner x-btn-inner-center' and contains(., 'Add')]"))).click()Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
Reference
You can find a detailed discussion on NoSuchElementException: no such element in Selenium “selenium.common.exceptions.NoSuchElementException” when using Chrome
The id seems to be dynamic one so you cannot use static id in the selector. You need to use a dynamic xpath for this.
You can use the below xpath:
driver.find_element(By.XPATH, "//span[contains(@id,'btnIconEl')]").click()
OR
You can find the element using its text as well in the xpath:
driver.find_element(By.XPATH, "//span[contains(text(),'Add Order')]").click()
It is important to see what you've tried and what problems did you have, but, judging by what was provided in the question, here is how you can locate the element by "name", by a "CSS selector" and by an "Xpath expression":
driver.findElement(By.name("amount"));
driver.findElement(By.cssSelector("input[name=amount]"));
driver.findElement(By.xpath("//input[@name='amount']"));
Possible issues:
- check if an element is inside an
iframeor not - if it is, you'll need to switch to the context of the frame and only then find the element - timing issue - the element might not be present when you are searching for it. In this case, use an Explicit Wait to wait for the element to be present
Firstly you have to look that whether element is present is any Frame. If the element is there in any Frame then you have to switch into that particular Frame by using below syntax:
driver().switchTo().frame("frameName");
driver().switchTo().frame("frameIndex");
You can also switch to the frame by giving its element like class, id etc.
driver().switchTo().frame(findElementByClassName("shrGoogleConnectIframe"));
Then you can locate the element using its any of the property mentioned.
driver.findElement(By.name("amount"));
driver.findElement(By.cssSelector("input[name=amount]"));
driver.findElement(By.xpath("//input[@name='amount']"));
Once you are able to locate the element, you have to switch back to the default content using below syntax:
driver.SwitchTo().DefaultContent();
In test automation services, the best practice is to use id, name and CSS selectors, Xpath should be given least priority.
hi guys why do I get this error?
selenium.common.exceptions.NoSuchElementException:
Message: no such element: Unable to locate element:
{"method":"name","selector":"user_name"}
Here is the "inspect code":
<input name="user_name" id="user_name" type="text"
class="form-control" value="" autocomplete="off">
and here is my python code:
from selenium import webdriver from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome(')
driver.get("https://mobilitie.service-now.com/")
search = driver.find_element_by_name("user_name")Im sorry, this is a stupid question but I was trying to figure this out for hours now :(
Looking at the page in question, the login form is contained within an iframe, which you will need to switch into, and then it looks like the form is loaded after a delay, so you will need to wait for the prescence of the element.
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://mobilitie.service-now.com/")
driver.switch_to.frame('gsft_main')
driver.find_element_by_id('user_name').send_keys('test')
driver.quit()
Silly answer, but have you tried changing the find_element_by_name to single quotes instead of double, ex: 'user_name' ? Most of the examples I can find for python for using the by_name feature use single quotes for the identifier.
Worst cause, you can try to use the css_selector version of identifying by id or name, '#user_name'.
I recommend using By, WebDriverWait, and expected_conditions in the place of .find_element_by_xpath.
After you click the paste button you will receive a permissions prompt. See below to get past it.
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.chrome.service import Service
import time
import pyautogui
service = Service('C:\\Path_To_Your\\chromedriver.exe')
driver = webdriver.Chrome(service=service)
driver.get('https://quillbot.com/')
paste_button = WebDriverWait(driver, 3).until(EC.visibility_of_element_located(
(By.XPATH, "//span[text()='Paste Text']")))
paste_button.click()
time.sleep(2)
pyautogui.press('tab')
pyautogui.press('tab')
pyautogui.press('enter')
This will work:
pasteXpath = "//button[contains(@class,'outlinedPrimary') and .//span[contains(text(),'Paste Text')]]"
element = w.find_element_by_xpath(pasteXpath).click()
Don't forget to add some wait / delay before it to make sure the page is fully loaded.