how to scroll down a webform in selenium python - selenium-webdriver

while i am running the scripts webdriver did not find the element.to find the elmement need to scroll down the webform .
i tried below code for scroll down the webform but it didn't workout
def scrolldown(self, attrib, attrib_val):
try:
logger.info("Executing : scrolldown")
self.wait_for_element_to_be_visible(attrib, attrib_val)
selector = self.get_selenium_selector(attrib)
self.browser.execute_script("window.scrollBy(0,700)"," ")
except Exception as e:
self.lib.screenshot_exception()
logger.info(e)
raise e

To scroll to end of page:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight)")
To scroll to any specific element:
driver.execute_script("arguments[0].scrollIntoView()", driver.find_element(
By.CSS_SELECTOR, "your_element_selector"))

Related

pyqgis plugin change QDialog to QMainWindow

I have a plugin window is QDialog, but I want to add QMenubar or QStatusBar
I have tried to find a way to convert QDialog to QMainWindow, but there is no result,
So I try to add QMenubar in QDialog again and everything works fine
Until the position of the object I added to the layout screen ran to the upper left corner.
I am not a native English speaker
def run(self):
"""Run method that performs all the real work"""
# Create the dialog with elements (after translation) and keep reference
# Only create GUI ONCE in callback, so that it will only load when the plugin is started
if self.first_start == True:
self.first_start = False
#建立menuBar的父節點物件
file_menu = QMenu("File")
#建立一個
open_action = QAction("Open",file_menu)
open_action.setShortcut('Alt+F4')
#把剛才建立的open action 加入file 節點
file_menu.addAction(open_action)
#建立一個menubar物件
menubar = QMenuBar(self.dlg)
#將父節點加入menubar
menubar.addMenu(file_menu)
#將self.dlg的menubar設定為menubar物件
self.dlg.setMenuBar(menubar)
# show the dialog
self.dlg.show()
# Run the dialog event loop
result = self.dlg.exec_()
# See if OK was pressed
if result:
# Do something useful here - delete the line containing pass and
# substitute with your code.
pass

Cannot locate option dropdown with value in selenium web driver

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("LOGON_selectedUser")));
WebElement mySelectElement = driver.findElement(By.id("LOGON_selectedUser"));
mySelectElement.click();
Select dropdown= new Select(driver.findElement(By.id("LOGON_selectedUser")));
dropdown.selectByVisibleText("HOTLINE-FAMILY SAFETY - Acting Supervisor");
Below is the error I'm getting:
Cannot locate option with text: HOTLINE-FAMILY SAFETY - Acting Supervisor
I tried with by. value bit no luck. :(
However, I'm able to select the dropdown with statement mySelectElement.click(); but when I try to select the drop-down, I'm keep on getting cannot locate the element. Pls help.
Here is the DOM:
enter image description here
The web page has been built using Angular. Please try to induce Explicit waits with Select class.
Select dropdown = new Select(wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//select[#name='selectedUser' and #id='LOGON_selectedUser' and #onchange]"))));
dropdown.selectByIndex(1);
or if that does not work, the below should work
((JavascriptExecutor) driver).executeScript("return document.getElementById('LOGON_selectedUser').selectedIndex = '" + index + "';)
where index is a variable, try to pass index number like 1,2,3 and so on...

Not able to get the locate the element by using xpath or css selector

<div class="et_pb_button_module_wrapper et_pb_button_4_tb_header_wrapper et_pb_button_alignment_center et_pb_button_alignment_phone_center et_pb_module ">
<a class="et_pb_button et_pb_button_4_tb_header full-width-btn et_hover_enabled et_pb_bg_layout_light" href="https://pegramonline.com/compare-insurance-companies-charlotte-nc/">Get a Quote</a>
</div>
I tried to locate <a> element and still it could not locate it..any other suggestion please...the class name has a space
By.cssSelector(“a[class=’et_pb_button et_pb_button_4_tb_header full-width-btn et_hover_enabled et_pb_bg_layout_light’]”);
By.cssSelector(“a.et_pb_button.et_pb_button_4_tb_header.full-width-btn.et_hover_enabled.et_pb_bg_layout_light”);
By.xpath(“//a[contains(#class, ‘et_pb_button’) and contains(#class, ‘et_pb_button_4_tb_header') and contains(#class, ‘full-width-btn')
and contains(#class, ‘et_hover_enabled’) and contains(#class, ‘et_pb_bg_layout_light’)]”);
It is working fine if you try to put a property color or anything else in this CODE
a.et_pb_button.et_pb_button_4_tb_header.full-width-btn.et_hover_enabled.et_pb_bg_layout_light{
color:red;
}
Or
a[class=’et_pb_button et_pb_button_4_tb_header full-width-btn et_hover_enabled et_pb_bg_layout_light’]{
color:red;
}
then you can easily understand that it's working fine.
There are 4 ways to click in Selenium.
Use the below xpath
//a[contains(text(),'Get a Quote')]
Code trial 1 :
Thread.sleep(5);
driver.findElement(By.xpath("//a[contains(text(),'Get a Quote')]")).click();
Code trial 2 :
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(text(),'Get a Quote')]"))).click();
Code trial 3 :
Thread.sleep(5);
WebElement button = driver.findElement(By.xpath("//a[contains(text(),'Get a Quote')]"));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", button);
Code trial 4 :
Thread.sleep(5);
WebElement button = driver.findElement(By.xpath("//a[contains(text(),'Get a Quote')]"));
new Actions(driver).moveToElement(button).click().build().perform();
PS : Please check in the dev tools (Google chrome) if we have unique entry in HTML DOM or not.
Steps to check:
Press F12 in Chrome -> go to element section -> do a CTRL + F -> then paste the xpath and see, if your desired element is getting highlighted with 1/1 matching node.

Unable to locate SVG elements through xpath on Kendo UI chart

I did try some of xpaths but seems no luck.
I want to click on country and then graph , Given below screenshot :
Website URL is : https://demos.telerik.com/kendo-ui/bar-charts/column
I tried xpaths :
//text(text()='India')
//g//text(text()='India')
Hi you can click India with the following Xpath //*[text()='India']
This is a really helpful resource
I usually open chrome inspector and then hit cntrl+F to open up an interactive way to test my xpaths:
You can target the svgs by using their strokes, but note these may change often. example: //*[#d='M54.5 164.5 L 70.5 164.5 70.5 236.5 54.5 236.5Z' and #stroke='#03a9f4']
The elements on chart are from SVG-namespace, so you cannot use common syntax to select those elements (you wouldn't be able to select element by its tag name, e.g. //svg or //path, etc)
You can try below to select text node with text "India":
//*[name()="text" and text()="India"]
As the desired elements are SVG Elements you need to consider the namespace and induce WebDriverWait for the desired element to be clickable and to click on the first bar within the graph you can use the following solution:
Code Block:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get("https://demos.telerik.com/kendo-ui/bar-charts/column")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[#id='chart']//*[name()='svg']//*[name()='g']//*[text()='India']//following::*[name()='path']"))).click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[#id='chart']//*[name()='svg']//*[name()='g'][contains(#clip-path, 'url')]//*[name()='path']"))).click()
Browser Snapshot:

ios 11 navigation bar overlap status bar

In ios 11 navigation bar is overlapping status bar. If any body faced the same issue kindly help.
Not sure if this is the same issue, but we ran into this as well when upgrading to iOS 11.
See ios 11 custom navbar goes under status bar
We were manually setting nav bar height to 64 and pinning to the superview edges. Conforming to the UINavigationBarDelegate protocol and implementing the UIBarPositioningDelegate delegate method solved it for us.
We replaced
navigationBar.autoPinEdgesToSuperviewEdgesExcludingEdge(.bottom)
navigationBar.autoSetDimension(.height, toSize: 64)
with
...
if #available(iOS 11.0, *) {
navigationBar.topAnchor.constraint(
equalTo: self.view.safeAreaLayoutGuide.topAnchor
).isActive = true
} else {
navigationBar.topAnchor.constraint(
equalTo: topLayoutGuide.bottomAnchor
).isActive = true
}
navigationBar.autoPinEdge(toSuperviewEdge: .left)
navigationBar.autoPinEdge(toSuperviewEdge: .right)
navigationBar.delegate = self
...
public func position(for bar: UIBarPositioning) -> UIBarPosition
return .topAttached
}
This is using the purelayout DSL for some of the autolayout calls (https://github.com/PureLayout/PureLayout)
Credit goes to https://stackoverflow.com/users/341994/matt for the answer
Had similar problem. In my case it turned out that previous view controller had custom nav bar and therefore it was hiding both - nav bar and status bar. There was
UIApplication.shared.setStatusBarHidden(true, with: UIStatusBarAnimation.none)
UIApplication.shared.setStatusBarStyle(.default, animated: false)
And in the problematic view controller I had this:
UIApplication.shared.setStatusBarStyle(.default, animated: false)
UIApplication.shared.setStatusBarHidden(false, with: UIStatusBarAnimation.none)
The issue was fixed simply by putting the two lines in the correct order:
UIApplication.shared.setStatusBarHidden(false, with: UIStatusBarAnimation.none)
UIApplication.shared.setStatusBarStyle(.default, animated: false)
All things above are deprecations, so another possible fix would probably be changing this to the recommended way of hiding status bar (which is not yet ideal as discussed here: setStatusBarHidden deprecated, but only thing that works).
Set child view to top constraint of superview... Click for edit constraint If you see "Align Top to : Safe Area " change it to superview so that it will overlap

Resources