I am running my test in Visual Studio 10, with C# and Selenium. There is a moment that Im landing on a page and I need to check some elements of the page, but its like "loading" continuously so its impossible to find this elements, cause are changing. The only way to find them is in Chrome Settings, Disable JavaScript and perfect it works. But how I disable Javascript with selenium in the same page, without call a new one? Just refreshing or smthg. Thx!!!
ElBandido
You can set that to profiler. Handling would be different based on how you want to do it
var firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("javascript.enabled", false);
See this
For Chrome
DesiredCapabilities caps = DesiredCapabilities.chrome();
caps.setCapability("chrome.switches", Arrays.asList("--disable-javascript"));
Taken from here
Related
I'm working on following scenario with WebDriver Sampler in Jmeter on javascript:
perform several requests in main window;
for 1 specific transaction:
2.1. - switch from initial window to newly created window (both windows have the same title),
2.2. - allow mic and cam (browser dialog box appears after new window is open and blocks activity of some page elements until cam and mic will not be allowed),
2.3. - find elements on page and perform actions with them (I wrote javascript snippets for that),
2.4. - close this 2nd window;
return back to initial main window;
proceed with requests in main window.
For steps 1 and 4 I have in js code all I need.
For step3, I suppose to use solution:
//switch back to initial main window:
WDS.browser.switchTo().defaultContent();
But I'm still stack on 2.1 and 2.2.
What is the best solution with 2.1, 2.2 and 2.4?
For 2.2. I tried to use "Set Preferences" section in Firefox WebDriver config and populate it with following:
Disadvantages:
1st - unfortunatelly, it doesn't work, and 2nd - I need these preferences working with Chrome, not only in FF.
Could you provide helpful tips, please, with 2.1, 2.2, 2.4?
I don't think this modal popup is a "window" controllable by WebDriver, it's rather a native window of the operating system hence you won't be able to interact with it using WebDriver functions, the options are in:
Simulate keyboard inputs using java.awt.Robot class
Locating the window using underlying operating system methods and sending the corresponding message to it, the entry point is JNI
Suppress these popups on browser startup level:
for Firefox you can load a custom profile with camera and mic allowed for the site you're testing
for Chromium and derivatives you can set the following ChromeOptions
use-fake-ui-for-media-stream
use-fake-device-for-media-stream
Unfortunately both approaches are not available out of the box for the Firefox Driver Config and Chrome Driver Config so you will have to switch to JSR223 Sampler and Groovy language for implementing your test scenario
I am trying to create a script to download an ebook into a pdf. When I try to use beautifulsoup in it I to print the contents of a single page, I get a message in the console stating "Oh no! It looks like JavaScript is disabled in your browser. Please re-enable to access the reader."
I have already enabled Javascript in Chrome and this same piece of code works for a page like a stackO answer page. What could be blocking Javascript in this page and how can I bypass it?
My code for reference:
url = requests.get("https://platform.virdocs.com/r/s/0/doc/350551/sp/14552484/mi/47443495/?cfi=%2F4%2F2%5BP7001013978000000000000000003FF2%5D%2F2%2F2%5BP7001013978000000000000000010019%5D%2F2%2C%2F1%3A0%2C%2F1%3A0")
url.raise_for_status()
soup = bs4.BeautifulSoup(url.text, "html.parser")
elems = soup.select("p")
print(elems[0].getText())
The problem is that the page actually contains no content. To load the content it needs to run some JS code. The requests.get method does not run JS, it just loads the basic HTML.
What you need to do is to emulate a browser, i.e. 'open' the page, run JS, and then scrape content. One way to do it is to use a browser driver as described here - https://stackoverflow.com/a/57912823/9805867
Can we make sure one particular browser session to bring to front/focus in parallel execution of selenium?
I have a requirement to do keyboard action by pressing enter key , using robot class to handle google payment option in chrome.
And robot key actions are working only when the browser is in focus/front side.
Tried with ((JavascriptExecutor) driver).executeScript("window.focus();"); but no effect.
Also , tried with sikuli , and having the same issue with sikuli too, as it also needs browser to be in focus.
NOT going for an alternative to use Autoit , since our project needs to work on both Windows and MAC.
Your help is much appreciated.
You can send keys (Alt + Tab)to switch to the current session of browser since it was just the window in focus and then moved to state of being not focused on.
Here is the code sample in Java
Actions action = new Actions(driver);
action.sendKeys(Keys.chord(Keys.ALT, Keys.ENTER)).build().perform();
I'm using QT 5.8 and trying to load webpage using QAxWidget (set to IE) that displays HTML 5 empty canvas.
QString url = "https://h3manth.com/demo/canvas/full-page.html";
ui.browser->dynamicCall("Navigate(const QString&)", url);
Running the same url directly in IE works fine.
But when running it from my simple QT application I'm getting script error:
And getting the blank view as a result even when pressing 'Yes' in the dialog.
Any ideas for possible solution?
Modifying the reg keys as described on msdn: msdn.microsoft.com/en-us/library/ee330730(v=vs.85).asp ensures using the intended IE version for "embedded" browser
I have a program that tests some of our sites with javascript disabled. It worked well, until we updated from WebDriver 2.4.5 to the latest. Now I get this error:
java.lang.IllegalArgumentException: Preference javascript.enabled may not be overridden: frozen value=true, requested value=false
It looks like the argument to disable JS is no longer allowed. I can't downgrade the WebDriver because the earlier versions don't work correctly with our updated Firefox.
What are my options for testing with JS disabled? I know Chrome never worked before, and now Firefox doesn't. I tried searching for "webdriver js disabled" but the results just bring back the javascript.enabled, false argument that no longer seems to work.
Best I could come up with is;
Create a new Firefox profile called NoJs by starting it with -P
Go to about:config and disable javascript there
Use this profile in selenium
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile profile = allProfiles.getProfile("NoJs");
WebDriver driver = new FirefoxDriver(profile);