I looked simillar questions at stackoverflow and didn't find anything that can help me.
I have following html code:
<span class="help-block ng-scope" translate="">Company</span>
How can i find this element (Java)? I tried following variants:
driver.findElement(By.cssSelector(".help-block.ng-scope"))
driver.findElement(By.xpath("//span[contains(#class, "Company")]"))
I even tried to just copy xpath from browser console in two ways:
First:
driver.findElement(By.xpath("//*[#id="ngCloudike"]/body/div[6]/div/div/div/div/form/div[1]/div[6]/span"))
Second:
driver.findElement(By.xpath("/html/body/div[6]/div/div/div/div/form/div[1]/div[6]/span"))
Also i tried to find By.ClassName, but i can't do this, because there are some spaces. So, how can i find element like this?
Try below expression:
driver.findElement(By.xpath("//span[text()='Company']"))
If you get NoSuchElementException with this code, try to add some time to wait until element present and visible:
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[text()='Company']"))
If you get NoSuchElementException even with ExplicitWait, target element might be located inside an iframe. To handle element inside an iframe:
driver.switchTo().frame("iframeNameOrId");
driver.findElement(By.xpath("//span[text()='Company']"));
Related
Tried executing the code but getting:
ElementNotInteractableException: element not interactable
for the below sendKeys statement. What could be the solution??
WebElement ss = driver.findElement(By.cssSelector("div[class='select__single-value css-1uccc91-singleValue']"));
ss.click();
ss.sendKeys("abc");
Generally <div> tags are not interactable unless [contenteditable="true"] (How to modify the innerHTML of a contenteditable element) is attribute is explicitly set.
Solution
If your usecase is to invoke click() / sendKeys() generally you have to invoke on <input> elements but not on <div>. Try to identify the element using the inspector opening the google-chrome-devtools and identify the desired <input> element.
References
You can find a couple of relevant detailed discussion on ElementNotInteractableException in:
Selenium WebDriver throws Exception in thread “main” org.openqa.selenium.ElementNotInteractableException
How to resolve ElementNotInteractableException: Element is not visible in Selenium webdriver?
Please make sure you are using the correct path as div tags are usually not interactable.
By.cssSelector("div[class='select__single-value css-1uccc91-singleValue']");
Here, you are using the compound class which is no longer allowed in selenium.
So, try using:
By.cssSelector("div[class='.select__single-value.css-1uccc91-singleValue']");
I am a beginner in selenium and I would like to press a file submission field.
I have already done a whole code to connect to the page, click on the buttons etc. (everything works, my driver is good)
But impossible to click on adding file
I looked on the internet how to do it, I added time, tried to browse the frames, used javascript for the hidden class... I tried all the buttons in the field and it doesn't detect them.
Add File
Source code
Thread.sleep(2000);
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0,1000)");
WebDriverWait wait = new WebDriverWait(driver, 60);// 1 minute
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*#id=\"yui_3_17_2_1_1584634673387_348\"]/div[1]/div[1]/a")));`
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[#id="yui_3_17_2_1_1584634673387_348"]/div[1]/div[1]/a"}
Do you have an idea ?
The primary issue I observed looking at the code is the incorrect locator in your Explicit Condition element checking line. It can be replaced with below code:
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#id='yui_3_17_2_1_1584634673387_348']/div[1]/div[1]/a")));
Basic XPath Syntax for reference though it has it's variations:
//tagname[#attrbute='value']
Additional advice Though I am not sure about the application you are automating, but the ID is likely to be changed. Based on the DOM Structure you have provided in the link above I would say change the locator to something on the lines of:
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[#role='button'][#title='Add..']")));
So what we have - there's an iFrame on page which shows a preview of previously generated data. I need to get element with text and then get CSS value from it.
Take a look at the DOM here:
example of the page
xpath to this element looks right to needed element (God save Chrome DevTools!).
But script cannot detect this element.
What I've did:
1 - switched to Iframe where my element is located - successfully.(no more iframe inside this iframe as per screenshot).
2 - tried to find element - NoSuchElementException.
Probably, such issue appears because of this #document thing ?If so - how do I can solve it and get to needed element with script ?
may be you need to wait till the frame to be loaded as given below.
WebDriverWait wait=new WebDriverWait(driver, 90);
driver=wait.untill(ExpectedConditions.frameToBeAvailableAndSwitchToIt("previewFrame");
WebElement element=driver.findElement(By.TagName("em"));
String fontStyle=element.getCssValue("font-sytle");
System.out.println(fontStyle);
Trying to find an xpath expression to use in:
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("XPATH HERE"))).click();
The element says "Invite Users" on the page and i need to be able to click on it
I need to find the element /a[#id='inviteUsers_8ef17ba4-b739-4fb6-8198-3862ea84c381_toggle'] but the problem is the characters after "inviteUsers_" is dynamically generated
I have already tried these:
"//*[contains(.,'Invite Users')]";
"//a[contains(.,'Invite Users')]";
And these give NoSuchElement exceptions.
This is the complete XPATH:
/html/body/div[#class='col-xs-10 col-xs-offset-2 main']/fieldset[#class='form-horizontal']/div[#id='roles']/div[#id='entitlements']/div[#class='panel panel-default '][3]/div[#id='service_8ef17ba4-b739-4fb6-8198-3862ea84c381']/div[#class='panel-body']/div[#class='panel panel-default'][1]/div[#class='panel-heading']/h4[#class='panel-title']/a[#id='inviteUsers_8ef17ba4-b739-4fb6-8198-3862ea84c381_toggle']
You can solve it with starts-with():
//a[starts-with(#id, "inviteUsers_")]
If this does not work try find a unique parent.
//div[contains(#id, 'service')]//a[contains(#id, 'inviteUsers')]
I am working on selenium, while running Java code I tried to CLICK a menu from the web page but encounter error of selenium.ElementNotVisibleException: Element is not currently visible Kindly advise on this matters . Thanks you
HTML code for text field :
<li onclick="goin('pages/AbcProxy/proxyGroupList.do')>
TESTABC
JAVA code:
WebdriverWait wait = new WebDriverWait(driver,50);
wait until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/div/div/ul/li[12]/a")));
presenceOfElementLocated checks if the element exists in the DOM. To check if the element is visible use visibilityOfElementLocated
WebdriverWait wait = new WebDriverWait(driver,50);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div/div/ul/li[12]/a")));
element.click();
It might be that your xpath is to a different a element that is invisible (css display none or such).
It would be better to use some id first (maybe for the parent ul?) and then a relative xpath from there, full xpaths from root are not recommended as it makes the test very brittle